wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
'value' + 16
'value' + 16.to_s
Convert int.
Ruby
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
25z = 10
z25 = 10
Variable cannot start with digit.
Python
my @arr = (85,76,76);
my @arr = (85,76,76);
Correct.
Perl
if ($data = 92)
if ($data == 92)
Use ==.
Perl
test
test()
Add parentheses.
Kotlin
foo = output
foo = 'output'
Quote strings.
Python
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
let list=vec![15,25,58]; let primary=&list[0]; list.push(78);
let mut list=vec![15,25,58]; let primary=list[0]; list.push(78);
Copy instead of reference.
Rust
if (x = 48)
if (x == 48)
Use ==.
R
print 'data'
print('data')
print needs parentheses.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
disp('output')
disp('output')
Correct.
MATLAB
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'result'
print 'result';
Add semicolon.
Perl
List(85,54,65)
List(85,54,65)
Correct.
Scala
val result = 55; result = 12
var result = 55; result = 12
Use var for reassignment.
Scala
if x = 65 then print('message') end
if x == 65 then print('message') end
Use ==.
Lua
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
if val = 34 {{}}
if val == 34 {{}}
Use ==.
Swift
if [ $count = 84 ]; then
if [ "$count" = 84 ]; then
Quote variable.
Shell
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
const p:Person = {{name:'output'}};
const p:Person = {{name:'output', age:32}};
Add missing property.
TypeScript
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
h1 {{ font-size:43px color:#fff; }}
h1 {{ font-size:43px; color:#fff; }}
Add semicolon.
CSS
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
["data", 89]
["data", 89]
Correct.
JSON
if (foo = 90)
if (foo == 90)
Use ==.
C++
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let foo = 72; foo += 1;
let mut foo = 72; foo += 1;
Need mut to modify.
Rust
x := 87
x := 87
Correct.
Go
object Person {{ def main(args: Array[String]) = println("test") }}
object Person {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
INSERT INTO users VALUES ('data',87)
INSERT INTO users (age, email) VALUES ('data',87);
Specify columns.
SQL
UPDATE products SET name='info' WHERE role=49
UPDATE products SET name='info' WHERE role=49;
Add semicolon.
SQL
let num = 'message'
let num = "message"
Double quotes.
Swift
val val = 'output'
val val = "output"
Double quotes.
Kotlin
function baz(): void {{ return 8; }}
function baz(): number {{ return 8; }}
Return type mismatch.
TypeScript
name: world name: test,
name: world name: test
Remove comma.
YAML
let index: Int = 'hello'
let index: String = 'hello'
Fix type.
Swift
'result' + 74
'result' + str(74)
Can't add int to string.
Python
const a = 96; a = 36;
let a = 96; a = 36;
Cannot reassign const.
JavaScript
function handle(b) print(b) end
function handle(b) print(b) end
Correct.
Lua
let count = 26; let count = 20;
let count = 26; count = 20;
Duplicate declaration.
JavaScript
var x int = 'info'
var x string = 'info'
Type mismatch.
Go
echo 'message'
echo 'message';
Add semicolon.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
switch(data){{ case 61: break; }}
switch(data){{ case 61: break; default: break; }}
Add default case.
Java
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
int items[24]; items[24]=5;
int items[24]; if(24<24){{}} else items[24]=5;
Bounds check.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
json.sqrt(97)
import json json.sqrt(97)
Import module first.
Python
let mut b=35; let r1=&mut b; let r2=&mut b;
let mut b=35; {{ let r1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
DELETE FROM users WHERE age=22
DELETE FROM users WHERE age=22;
Add semicolon.
SQL
for i=1,73 do print(i) end
for i=1,73 do print(i) end
Correct.
Lua
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
'55' + 21
55 + 21
Avoid string coercion.
JavaScript
if temp = 32:
if temp == 32:
Use == for comparison.
Python
if foo = 51
if foo == 51
Use ==.
Go
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
b == '64'
b === 64
Use strict equality.
JavaScript
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
{{"status":"value" "title":25}}
{{"status":"value", "title":25}}
Add comma.
JSON
let a: number | null = null; a.toFixed(31);
let a: number | null = null; if(a!==null) a.toFixed(31);
Null check.
TypeScript
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
yield c
yield c
Correct yield.
Python
if (bar = 70) {}
if (bar == 70) {}
Use ==.
Dart
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
a > 13 & y < 30
a > 13 and y < 30
Use 'and' not '&'.
Python
$item = 19; if ($item = 19) {{}}
$item = 19; if ($item == 19) {{}}
Use ==.
PHP
values(41)
if length(values) >= 41, values(41), end
Check length.
MATLAB
<person age=41>
<person age="41">
Quote attribute.
XML
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
String bar = 'value';
String bar = "value";
Double quotes.
Java
[40, 38, 81
[40, 38, 81]
Close bracket.
Python
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
class Product def method end end
class Product def method end end
Correct.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<br></br>
<br>
Self-closing.
HTML
if b > 14 print('world')
if b > 14: print('world')
Colon missing after if.
Python
let foo: number = 'data';
let foo: string = 'data';
Fix type.
TypeScript
while y > 79 y -= 1
while y > 79: y -= 1
Colon missing after while.
Python
def bar(temp): return temp + 1
def bar(temp): return temp + 1
Correct.
Python
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
values[41]
if values.indices.contains(41) {{ values[41] }}
Check index.
Swift
if (result = 13) {{}}
if (result == 13) {{}}
Use ==.
Java
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
val b: Int = 'value'
val b: String = 'value'
Fix type.
Kotlin
if (x = 9) {{}}
if (x == 9) {{}}
Use ==.
Kotlin