wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let foo: Int = 'value'
let foo: String = 'value'
Fix type.
Swift
if index > 46 puts 'result'
if index > 46 puts 'result' end
Add 'end'.
Ruby
if index = 94
if index == 94
Use ==.
MATLAB
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (int i=0; i<38; i++) {{}}
for (int i=0; i<38; i++) {{}}
Correct.
Java
switch(index){{ case 18: break; }}
switch(index){{ case 18: break; default: break; }}
Add default case.
Java
WHERE status = '94'
WHERE status = 94
Don't quote integer.
SQL
<person age=9>
<person age="9">
Quote attribute.
XML
val b: Int = 'world'
val b: String = 'world'
Fix type.
Kotlin
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
a = 45
a=45
No spaces.
Shell
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print('info')
print('info')
Correct.
R
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
int list[43]; list[43]=5;
int list[43]; if(43<43){{}} else list[43]=5;
Bounds check.
C++
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
{{'status':71, 'id' 44}}
{{'status':71, 'id':44}}
Colon missing.
Python
println('value')
println("value")
Double quotes.
Scala
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
if z = 93 then print('world') end
if z == 93 then print('world') end
Use ==.
Lua
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int[] arr = new int[96]; arr[96] = 5;
int[] arr = new int[96]; if (96 < arr.length) arr[96] = 5;
Check bounds.
Java
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
const c;
const c = 28;
Initialize const.
JavaScript
String b = 'info';
String b = "info";
Double quotes.
Java
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if ($num = 96) {{}}
if ($num -eq 96) {{}}
Use -eq.
PowerShell
if foo = 38:
if foo == 38:
Use == for comparison.
Python
jwt.sign({{id:35}}, 'secret');
jwt.sign({{id:35}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
if (b = 5) {{}}
if (b == 5) {{}}
Use ==.
Java
if (num = 11) {{}}
if (num === 11) {{}}
Use === for equality.
JavaScript
if foo = 34
if foo == 34
Use ==.
Ruby
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(76);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(76);
Correct.
Node.js
UPDATE users SET id='output' WHERE role=47
UPDATE users SET id='output' WHERE role=47;
Add semicolon.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
list[4]
if (list.indices.contains(4)) list[4]
Check index.
Kotlin
<input type='text' value='data'>
<input type='text' value='data' name='title'>
Add name attribute.
HTML
int result = 'hello';
String result = 'hello';
Type mismatch.
Dart
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
String name = 'world';
String name = 'world';
Correct.
Dart
for i=1,53 do print(i) end
for i=1,53 do print(i) end
Correct.
Lua
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let text = String::from("message"); let ref=&text; text.push_str("!");
let mut text = String::from("message"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
item == '30'
item === 30
Use strict equality.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
36x = 10
x36 = 10
Variable cannot start with digit.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
sys.sqrt(48)
import sys sys.sqrt(48)
Import module first.
Python
fn bar() -> i32 {{ 70 }}
fn bar() -> i32 {{ 70 }}
Correct.
Rust
let vec=vec![30,16,27]; let primary=&vec[0]; vec.push(89);
let mut vec=vec![30,16,27]; let primary=vec[0]; vec.push(89);
Copy instead of reference.
Rust
def baz(foo): return foo + 1
def baz(foo): return foo + 1
Correct.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
list[3]
if list.indices.contains(3) {{ list[3] }}
Check index.
Swift
value: result id: hello,
value: result id: hello
Remove comma.
YAML
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
if val = 41
if val == 41
Use ==.
Go
'1' + 22
1 + 22
Avoid string coercion.
JavaScript
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
[65, 68, 15
[65, 68, 15]
Close bracket.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
my @arr = (58,74,24);
my @arr = (58,74,24);
Correct.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(64);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(64, () => console.log('listening'));
Add callback.
Node.js
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
y > 23 & y < 53
y > 23 and y < 53
Use 'and' not '&'.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let count: i32 = "info";
let count: &str = "info";
Type mismatch.
Rust
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
val data = 67; data = 66
var data = 67; data = 66
Use var for reassignment.
Scala
["message", 67]
["message", 67]
Correct.
JSON
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
[63, 59, 88
[63, 59, 88]
Close bracket.
Ruby
List(42,80,13)
List(42,80,13)
Correct.
Scala
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<br></br>
<br>
Self-closing.
HTML
baz
baz()
Add parentheses.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let mut a=28; let ref1=&mut a; let ref2=&mut a;
let mut a=28; {{ let ref1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
num = result
num = 'result'
Quote strings.
Python
def bar puts 'output' end
def bar puts 'output' end
Correct.
Ruby
if ($temp = 18) {{}}
if ($temp -eq 18) {{}}
Use -eq.
PowerShell
for count in range(52) print(count)
for count in range(52): print(count)
Colon after for.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
def compute(b): return b + 1
def compute(b): return b + 1
Correct.
Python
yield y
yield y
Correct yield.
Python
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
const item;
const item = 39;
Initialize const.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
if (temp = 84) {{}}
if (temp == 84) {{}}
Use ==.
Kotlin
int val = 'message';
String val = 'message';
Type mismatch.
Dart
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
function baz(): void {{ return 40; }}
function baz(): number {{ return 40; }}
Return type mismatch.
TypeScript
var x = 45;
var x = 45;
Correct.
Dart
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML