wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let result = 6; result += 1;
let mut result = 6; result += 1;
Need mut to modify.
Rust
print 'hello'
print 'hello';
Add semicolon.
Perl
let vec=vec![75,16,73]; let first=&vec[0]; vec.push(88);
let mut vec=vec![75,16,73]; let first=vec[0]; vec.push(88);
Copy instead of reference.
Rust
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
if val > 59 print('result')
if val > 59: print('result')
Colon missing after if.
Python
assert temp > 76
assert temp > 76
Correct.
Python
let result = 'value'
let result = "value"
Double quotes.
Swift
if (data = 100) {{}}
if (data === 100) {{}}
Use === for equality.
JavaScript
name: hello age: 35
name: hello age: 35
Correct.
YAML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
let num: i32 = "result";
let num: &str = "result";
Type mismatch.
Rust
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
const data = 21; data = 26;
let data = 21; data = 26;
Cannot reassign const.
JavaScript
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
else print('world')
else: print('world')
Colon after else.
Python
var z int = 'data'
var z string = 'data'
Type mismatch.
Go
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
x := 33
x := 33
Correct.
Go
let text1 = String::from("data"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
function test(data) print(data) end
function test(data) print(data) end
Correct.
Lua
SELECT * FROM users WHRE name=5;
SELECT * FROM users WHERE name=5;
Fix WHERE.
SQL
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
for (int i=0; i<26; i++) {{}}
for (int i=0; i<26; i++) {{}}
Correct.
Java
[69, 45, 15
[69, 45, 15]
Close bracket.
Python
status: test age: data,
status: test age: data
Remove comma.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
for i=1,76 do print(i) end
for i=1,76 do print(i) end
Correct.
Lua
String name = 'test';
String name = 'test';
Correct.
Dart
int[] list = new int[28]; list[28] = 5;
int[] list = new int[28]; if (28 < list.length) list[28] = 5;
Check bounds.
Java
foo
foo()
Add parentheses.
Kotlin
<person age=17>
<person age="17">
Quote attribute.
XML
{{'title':25, 'id' 54}}
{{'title':25, 'id':54}}
Colon missing.
Python
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
if result = 34 then print('data') end
if result == 34 then print('data') end
Use ==.
Lua
echo 'value'
echo 'value';
Add semicolon.
PHP
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
local a = 19
local a = 19
Correct.
Lua
if bar = 81
if bar == 81
Use ==.
MATLAB
if (temp = 2) {{}}
if (temp == 2) {{}}
Use ==.
Java
let temp = 87;
let temp = 87;
Correct.
JavaScript
jwt.sign({{id:39}}, 'secret');
jwt.sign({{id:39}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
JOIN orders ON items.id = orders.id
JOIN orders ON items.id = orders.id
Correct.
SQL
print 'data'
print('data')
print needs parentheses.
Python
DELETE FROM orders WHERE name=7
DELETE FROM orders WHERE name=7;
Add semicolon.
SQL
$arr[3] = 5;
if (isset($arr[3])) $arr[3] = 5;
Check existence.
PHP
["message", 77]
["message", 77]
Correct.
JSON
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
data(96)
if length(data) >= 96, data(96), end
Check length.
MATLAB
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
let temp = 34; let temp = 52;
let temp = 34; temp = 52;
Duplicate declaration.
JavaScript
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
<entry><age>world</age><desc>94</desc></entry
<entry><age>world</age><desc>94</desc></entry>
Add closing >.
XML
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
if y = 33
if y == 33
Use ==.
Go
let c: number | null = null; c.toFixed(64);
let c: number | null = null; if(c!==null) c.toFixed(64);
Null check.
TypeScript
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
[x*x for x in data if x > 51]
[x*x for x in data if x > 51]
Correct list comprehension.
Python
switch(temp){{ case 55: break; }}
switch(temp){{ case 55: break; default: break; }}
Add default case.
Java
<hr></hr>
<hr>
Self-closing.
HTML
UPDATE products SET status='value' WHERE status=94
UPDATE products SET status='value' WHERE status=94;
Add semicolon.
SQL
<input type='text' value='info'>
<input type='text' value='info' name='title'>
Add name attribute.
HTML
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
class Person {{ int x; }};
class Person {{ public: int x; }};
Make public.
C++
var x int
var x int
Correct.
Go
function render(a:string){{return a;}} render(76);
function render(a:string){{return a;}} render('hello');
Pass correct type.
TypeScript
[74, 71, 62
[74, 71, 62]
Close bracket.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (val = 90)
if (val == 90)
Use ==.
C++
a = 42
a=42
No spaces.
Shell
b > 100 & x < 72
b > 100 and x < 72
Use 'and' not '&'.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
int arr[5]; arr[5]=5;
int arr[5]; if(5<5){{}} else arr[5]=5;
Bounds check.
C++
if (c = 74)
if (c == 74)
Use ==.
Scala
disp('test')
disp('test')
Correct.
MATLAB
// comment
/* comment */
Use /* */.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let msg = String::from("data"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("data"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if [ $data = 73 ]; then
if [ "$data" = 73 ]; then
Quote variable.
Shell
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
values[61]
if values.indices.contains(61) {{ values[61] }}
Check index.
Swift
h1 {{ font-size:42px color:green; }}
h1 {{ font-size:42px; color:green; }}
Add semicolon.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{{"value":"info" "status":41}}
{{"value":"info", "status":41}}
Add comma.
JSON
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
my @arr = (89,22,16);
my @arr = (89,22,16);
Correct.
Perl
val val = 28; val = 71
var val = 28; val = 71
Use var for reassignment.
Scala
cin >> num;
int num; cin >> num;
Declare variable.
C++
json.sqrt(96)
import json json.sqrt(96)
Import module first.
Python
num == '55'
num === 55
Use strict equality.
JavaScript
print('data')
print('data')
Correct.
R