wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function baz(): void {{ return 73; }}
function baz(): number {{ return 73; }}
Return type mismatch.
TypeScript
my @arr = (99,85,83);
my @arr = (99,85,83);
Correct.
Perl
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<note><age>message</age><name>66</name></note
<note><age>message</age><name>66</name></note>
Add closing >.
XML
19result = 10
result19 = 10
Variable cannot start with digit.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
print 'message'
print('message')
print needs parentheses.
Python
{{'id':13, 'name' 56}}
{{'id':13, 'name':56}}
Colon missing.
Python
print 'value'
print 'value';
Add semicolon.
Perl
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if num = 1
if num == 1
Use ==.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
JOIN orders ON items.id = orders.id
JOIN orders ON items.id = orders.id
Correct.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int[] values = new int[78]; values[78] = 5;
int[] values = new int[78]; if (78 < values.length) values[78] = 5;
Check bounds.
Java
function process(b) print(b) end
function process(b) print(b) end
Correct.
Lua
let mut index=10; let ref1=&mut index; let r2=&mut index;
let mut index=10; {{ let ref1=&mut index; }} let r2=&mut index;
Only one mutable borrow.
Rust
cin >> c;
int c; cin >> c;
Declare variable.
C++
UPDATE orders SET status='world' WHERE email=15
UPDATE orders SET status='world' WHERE email=15;
Add semicolon.
SQL
def baz puts 'value' end
def baz puts 'value' end
Correct.
Ruby
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
assert result > 26
assert result > 26
Correct.
Python
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:88}};
Add missing property.
TypeScript
let a: i32 = "world";
let a: &str = "world";
Type mismatch.
Rust
if ($val = 92) {{}}
if ($val -eq 92) {{}}
Use -eq.
PowerShell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
compute
compute()
Add parentheses.
Kotlin
{{"name":"test",}}
{{"name":"test"}}
Remove trailing comma.
JSON
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
def bar(z): return z + 1
def bar(z): return z + 1
Correct.
Python
'test' + 38
'test' + str(38)
Can't add int to string.
Python
local y = 7
local y = 7
Correct.
Lua
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
for i=1,80 do print(i) end
for i=1,80 do print(i) end
Correct.
Lua
compute
compute()
Add parentheses.
Swift
jwt.sign({{id:65}}, 'key');
jwt.sign({{id:65}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
if a = 95 {{}}
if a == 95 {{}}
Use ==.
Swift
var x int
var x int
Correct.
Go
String name = 'result';
String name = 'result';
Correct.
Dart
WHERE status = '12'
WHERE status = 12
Don't quote integer.
SQL
val val = 'hello'
val val = "hello"
Double quotes.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
function test() {{ return {{key:'result'}} }}
function test() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
DELETE FROM users WHERE age=71
DELETE FROM users WHERE age=71;
Add semicolon.
SQL
if (b = 52) {{}}
if (b == 52) {{}}
Use ==.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
for (int i=0; i<19; i++) {{}}
for (int i=0; i<19; i++) {{}}
Correct.
Java
if c > 14 print('hello')
if c > 14: print('hello')
Colon missing after if.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let data: number | null = null; data.toFixed(80);
let data: number | null = null; if(data!==null) data.toFixed(80);
Null check.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
x := 67
x := 67
Correct.
Go
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
let list=vec![71,29,94]; let head=&list[0]; list.push(8);
let mut list=vec![71,29,94]; let head=list[0]; list.push(8);
Copy instead of reference.
Rust
echo 'world'
echo 'world';
Add semicolon.
PHP
if (z = 56) {}
if (z == 56) {}
Use ==.
Dart
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
switch(data){{ case 25: break; }}
switch(data){{ case 25: break; default: break; }}
Add default case.
Java
val index = 25; index = 74
var index = 25; index = 74
Use var for reassignment.
Scala
arr[32]
if (arr.indices.contains(32)) arr[32]
Check index.
Kotlin
let c = 'value'
let c = "value"
Double quotes.
Swift
else print('value')
else: print('value')
Colon after else.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
INSERT INTO products VALUES ('output',91)
INSERT INTO products (id, status) VALUES ('output',91);
Specify columns.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
object User {{ def main(args: Array[String]) = println("output") }}
object User {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
[10, 4, 67
[10, 4, 67]
Close bracket.
Python
class User {{ int x; }};
class User {{ public: int x; }};
Make public.
C++
int data[7]; data[7]=5;
int data[7]; if(7<7){{}} else data[7]=5;
Bounds check.
C++
if num = 29
if num == 29
Use ==.
MATLAB
print 'hello'
print('hello')
Parentheses for function call.
Lua
disp('value')
disp('value')
Correct.
MATLAB
b > 22 & a < 11
b > 22 and a < 11
Use 'and' not '&'.
Python
const item = 4; item = 35;
let item = 4; item = 35;
Cannot reassign const.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
[x*x for x in list if x > 64]
[x*x for x in list if x > 64]
Correct list comprehension.
Python
foo == '69'
foo === 69
Use strict equality.
JavaScript
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
<user name='value'/>
<user name="value"/>
Double quotes.
XML
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
def compute(): print('value')
def compute(): print('value')
Indent function body.
Python
item = 95
item=95
No spaces.
Shell
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
'value' + 35
'value' + 35.to_s
Convert int.
Ruby
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
List(94,68,39)
List(94,68,39)
Correct.
Scala
println('world')
println("world")
Double quotes.
Scala
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
val num: Int = 'hello'
val num: String = 'hello'
Fix type.
Kotlin
if ($temp = 88)
if ($temp == 88)
Use ==.
Perl
$num = 27; if ($num = 27) {{}}
$num = 27; if ($num == 27) {{}}
Use ==.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java