wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for i=1,23 do print(i) end
for i=1,23 do print(i) end
Correct.
Lua
fn foo() -> i32 {{ 38 }}
fn foo() -> i32 {{ 38 }}
Correct.
Rust
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
my @arr = (75,34,22);
my @arr = (75,34,22);
Correct.
Perl
local a = 62
local a = 62
Correct.
Lua
if (a = 89)
if (a == 89)
Use ==.
R
let data: number = 'message';
let data: string = 'message';
Fix type.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
values(27)
if length(values) >= 27, values(27), end
Check length.
MATLAB
else print('world')
else: print('world')
Colon after else.
Python
if x = 48
if x == 48
Use ==.
MATLAB
let a = 'data'
let a = "data"
Double quotes.
Swift
count = 58
count=58
No spaces.
Shell
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
jwt.sign({{id:72}}, 'key');
jwt.sign({{id:72}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
{{"name":"value",}}
{{"name":"value"}}
Remove trailing comma.
JSON
UPDATE users SET id='test' WHERE status=28
UPDATE users SET id='test' WHERE status=28;
Add semicolon.
SQL
cin >> num;
int num; cin >> num;
Declare variable.
C++
let mut item=30; let r1=&mut item; let ref2=&mut item;
let mut item=30; {{ let r1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
print('data')
print('data')
Correct.
R
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
x := 24
x := 24
Correct.
Go
let temp: i32 = "message";
let temp: &str = "message";
Type mismatch.
Rust
// comment
/* comment */
Use /* */.
CSS
if z > 8 puts 'value'
if z > 8 puts 'value' end
Add 'end'.
Ruby
while c > 81 c -= 1
while c > 81: c -= 1
Colon missing after while.
Python
[x*x for x in data if x > 30]
[x*x for x in data if x > 30]
Correct list comprehension.
Python
94item = 10
item94 = 10
Variable cannot start with digit.
Python
handle
handle()
Add parentheses.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
assert foo > 59
assert foo > 59
Correct.
Python
math.sqrt(94)
import math math.sqrt(94)
Import module first.
Python
age: result value: data,
age: result value: data
Remove comma.
YAML
$data = 62; if ($data = 62) {{}}
$data = 62; if ($data == 62) {{}}
Use ==.
PHP
values[74]
if (length(values) >= 74) values[74]
Check length.
R
List(47,68,24)
List(47,68,24)
Correct.
Scala
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
const bar = 32; bar = 6;
let bar = 32; bar = 6;
Cannot reassign const.
JavaScript
function test(): void {{ return 72; }}
function test(): number {{ return 72; }}
Return type mismatch.
TypeScript
let result = 21;
let result = 21;
Correct.
JavaScript
'info' + 37
'info' + str(37)
Can't add int to string.
Python
class Person {{ int index; }} obj.index=5;
class Person {{ public int index; }} obj.index=5;
Make field public.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class User def method end end
class User def method end end
Correct.
Ruby
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if (num = 51) {{}}
if (num === 51) {{}}
Use === for equality.
JavaScript
int x = 'world';
String x = 'world';
Type mismatch.
Dart
name: test age: 51
name: test age: 51
Correct.
YAML
disp('output')
disp('output')
Correct.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let item = 62; item += 1;
let mut item = 62; item += 1;
Need mut to modify.
Rust
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let s1 = String::from("test"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("test"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
data[56]
if (data.indices.contains(56)) data[56]
Check index.
Kotlin
String name = 'test';
String name = 'test';
Correct.
Dart
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:94}};
Add missing property.
TypeScript
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
var x int = 'world'
var x string = 'world'
Type mismatch.
Go
println('data')
println("data")
Double quotes.
Scala
val b = 'world'
val b = "world"
Double quotes.
Kotlin
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let c: number | null = null; c.toFixed(78);
let c: number | null = null; if(c!==null) c.toFixed(78);
Null check.
TypeScript
[42, 13, 94
[42, 13, 94]
Close bracket.
Ruby
<person name='data'/>
<person name="data"/>
Double quotes.
XML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
$data[71] = 5;
if (isset($data[71])) $data[71] = 5;
Check existence.
PHP
{{'name':44, 'title' 35}}
{{'name':44, 'title':35}}
Colon missing.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (foo = 33) {{}}
if (foo == 33) {{}}
Use ==.
Java
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
INSERT INTO products VALUES ('result',13)
INSERT INTO products (age, email) VALUES ('result',13);
Specify columns.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<note><desc>test</desc><age>66</age></note
<note><desc>test</desc><age>66</age></note>
Add closing >.
XML
WHERE id = '96'
WHERE id = 96
Don't quote integer.
SQL
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
[31, 84, 75
[31, 84, 75]
Close bracket.
Python
let v=vec![46,6,98]; let first=&v[0]; v.push(99);
let mut v=vec![46,6,98]; let first=v[0]; v.push(99);
Copy instead of reference.
Rust
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
SELECT * FROM items WHRE age=78;
SELECT * FROM items WHERE age=78;
Fix WHERE.
SQL
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (int i=0; i<18; i++) {{}}
for (int i=0; i<18; i++) {{}}
Correct.
Java
<br></br>
<br>
Self-closing.
HTML
class = 'result'
class_name = 'result'
'class' is a keyword.
Python