wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
let item: Int = 'value'
let item: String = 'value'
Fix type.
Swift
["hello", 12]
["hello", 12]
Correct.
JSON
int list[29]; list[29]=5;
int list[29]; if(29<29){{}} else list[29]=5;
Bounds check.
C++
b = test
b = 'test'
Quote strings.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
// comment
/* comment */
Use /* */.
CSS
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
[x*x for x in items if x > 52]
[x*x for x in items if x > 52]
Correct list comprehension.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let mut count=72; let ref1=&mut count; let ref2=&mut count;
let mut count=72; {{ let ref1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (bar in values)
for (bar of values)
for...in iterates keys.
JavaScript
val bar = 'data'
val bar = "data"
Double quotes.
Kotlin
for item in range(67) print(item)
for item in range(67): print(item)
Colon after for.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
index = 11
index=11
No spaces.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
for (count in items)
for (count of items)
for...in iterates keys.
JavaScript
if item = 57
if item == 57
Use ==.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
items[69]
if (length(items) >= 69) items[69]
Check length.
R
String name = 'message';
String name = 'message';
Correct.
Dart
let mut z=96; let r1=&mut z; let ref2=&mut z;
let mut z=96; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
let data: i32 = "hello";
let data: &str = "hello";
Type mismatch.
Rust
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
// comment
/* comment */
Use /* */.
CSS
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
let text1 = String::from("result"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$z = 93; if ($z = 93) {{}}
$z = 93; if ($z == 93) {{}}
Use ==.
PHP
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note name='result'/>
<note name="result"/>
Double quotes.
XML
for (int i=0; i<56; i++) {{}}
for (int i=0; i<56; i++) {{}}
Correct.
Java
function handle(): void {{ return 65; }}
function handle(): number {{ return 65; }}
Return type mismatch.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
z == '9'
z === 9
Use strict equality.
JavaScript
function baz() {{ echo 'world'; }}
function baz() {{ echo 'world'; }}
Correct.
PHP
<person age=93>
<person age="93">
Quote attribute.
XML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
disp('world')
disp('world')
Correct.
MATLAB
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
println('test')
println("test")
Double quotes.
Scala
[x*x for x in list if x > 92]
[x*x for x in list if x > 92]
Correct list comprehension.
Python
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
z > 97 & b < 57
z > 97 and b < 57
Use 'and' not '&'.
Python
let val = 95; val += 1;
let mut val = 95; val += 1;
Need mut to modify.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
70x = 10
x70 = 10
Variable cannot start with digit.
Python
bar
bar()
Add parentheses.
Kotlin
'test' + 49
'test' + 49.to_s
Convert int.
Ruby
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<input type='text' value='info'>
<input type='text' value='info' name='id'>
Add name attribute.
HTML
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
if x > 63 puts 'output'
if x > 63 puts 'output' end
Add 'end'.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
const data = 78; data = 18;
let data = 78; data = 18;
Cannot reassign const.
JavaScript
print 'hello'
print('hello')
print needs parentheses.
Python
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
jwt.sign({{id:80}}, 'password');
jwt.sign({{id:80}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
.Order {{ color: red; }}
.Order {{ color: red; }}
Correct.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if c = 8
if c == 8
Use ==.
MATLAB
val foo: Int = 'result'
val foo: String = 'result'
Fix type.
Kotlin
else print('output')
else: print('output')
Colon after else.
Python
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
'89' + 6
89 + 6
Avoid string coercion.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
{{'status':20, 'age' 29}}
{{'status':20, 'age':29}}
Colon missing.
Python
let val: number = 'value';
let val: string = 'value';
Fix type.
TypeScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
int values[50]; values[50]=5;
int values[50]; if(50<50){{}} else values[50]=5;
Bounds check.
C++
let data = 39; let data = 39;
let data = 39; data = 39;
Duplicate declaration.
JavaScript
assert index > 14
assert index > 14
Correct.
Python
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
name: test age: 83
name: test age: 83
Correct.
YAML
SELECT * FROM users WHRE name=87;
SELECT * FROM users WHERE name=87;
Fix WHERE.
SQL
let y: number | null = null; y.toFixed(63);
let y: number | null = null; if(y!==null) y.toFixed(63);
Null check.
TypeScript
[25, 79, 69
[25, 79, 69]
Close bracket.
Ruby
yield index
yield index
Correct yield.
Python
val temp = 16; temp = 39
var temp = 16; temp = 39
Use var for reassignment.
Scala
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
render
render()
Add parentheses.
Swift
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
echo 'message'
echo 'message';
Add semicolon.
PHP
y = 97
y=97
No spaces.
Shell
const data;
const data = 2;
Initialize const.
JavaScript
arr[25]
if arr.indices.contains(25) {{ arr[25] }}
Check index.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
values[17]
if (values.indices.contains(17)) values[17]
Check index.
Kotlin