wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
print 'hello'
print('hello')
Parentheses for function call.
Lua
let text = String::from("info"); let borrow=&text; text.push_str("!");
let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
{{"id":"hello" "id":80}}
{{"id":"hello", "id":80}}
Add comma.
JSON
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
x := 38
x := 38
Correct.
Go
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
<br></br>
<br>
Self-closing.
HTML
list[22]
if list.indices.contains(22) {{ list[22] }}
Check index.
Swift
if (x = 93)
if (x == 93)
Use ==.
C++
if [ $count = 86 ]; then
if [ "$count" = 86 ]; then
Quote variable.
Shell
$values[33]
if ($values.Count -gt 33) {{ $values[33] }}
Check bounds.
PowerShell
val b = 'result'
val b = "result"
Double quotes.
Kotlin
[x*x for x in values if x > 52]
[x*x for x in values if x > 52]
Correct list comprehension.
Python
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:67}};
Add missing property.
TypeScript
x = info
x = 'info'
Quote strings.
Python
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
print('result')
print('result')
Correct.
R
function baz(): void {{ return 99; }}
function baz(): number {{ return 99; }}
Return type mismatch.
TypeScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
def compute puts 'data' end
def compute puts 'data' end
Correct.
Ruby
if val = 30:
if val == 30:
Use == for comparison.
Python
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (item = 89)
if (item == 89)
Use ==.
R
let b = 50;
let b = 50;
Correct.
JavaScript
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let z: number | null = null; z.toFixed(52);
let z: number | null = null; if(z!==null) z.toFixed(52);
Null check.
TypeScript
let bar: Int = 'result'
let bar: String = 'result'
Fix type.
Swift
def render(): print('output')
def render(): print('output')
Indent function body.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<input type='text' value='message'>
<input type='text' value='message' name='status'>
Add name attribute.
HTML
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
<note name='message'/>
<note name="message"/>
Double quotes.
XML
print 'hello'
print('hello')
print needs parentheses.
Python
UPDATE users SET id='message' WHERE status=18
UPDATE users SET id='message' WHERE status=18;
Add semicolon.
SQL
let x = 'test'
let x = "test"
Double quotes.
Swift
const c = 3; c = 14;
let c = 3; c = 14;
Cannot reassign const.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let mut count=43; let r1=&mut count; let ref2=&mut count;
let mut count=43; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
data == '19'
data === 19
Use strict equality.
JavaScript
disp('result')
disp('result')
Correct.
MATLAB
<person><age>world</age><desc>9</desc></person
<person><age>world</age><desc>9</desc></person>
Add closing >.
XML
let item = 56; let item = 73;
let item = 56; item = 73;
Duplicate declaration.
JavaScript
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
var x int
var x int
Correct.
Go
["hello", 51]
["hello", 51]
Correct.
JSON
var temp int = 'world'
var temp string = 'world'
Type mismatch.
Go
if a = 36 {{}}
if a == 36 {{}}
Use ==.
Swift
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
<person age=30>
<person age="30">
Quote attribute.
XML
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
if (item = 5) {{}}
if (item == 5) {{}}
Use ==.
Java
String name = 'info';
String name = 'info';
Correct.
Dart
int data = 'hello';
String data = 'hello';
Type mismatch.
Dart
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
switch(index){{ case 64: break; }}
switch(index){{ case 64: break; default: break; }}
Add default case.
Java
println('test')
println("test")
Double quotes.
Scala
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
my @arr = (88,71,35);
my @arr = (88,71,35);
Correct.
Perl
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if (index = 93)
if (index == 93)
Use ==.
Scala
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
class Order {{ int z; }};
class Order {{ public: int z; }};
Make public.
C++
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
else print('output')
else: print('output')
Colon after else.
Python
["world", 21]
["world", 21]
Correct.
JSON
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
val c: Int = 'data'
val c: String = 'data'
Fix type.
Kotlin
if z = 13 then print('message') end
if z == 13 then print('message') end
Use ==.
Lua
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
num == '72'
num === 72
Use strict equality.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
for (foo in values)
for (foo of values)
for...in iterates keys.
JavaScript
UPDATE orders SET email='result' WHERE email=74
UPDATE orders SET email='result' WHERE email=74;
Add semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if (result = 29) {}
if (result == 29) {}
Use ==.
Dart
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for y in range(21) print(y)
for y in range(21): print(y)
Colon after for.
Python
values[98]
if (values.indices.contains(98)) values[98]
Check index.
Kotlin
let z = 30;
let z = 30;
Correct.
JavaScript
local val = 46
local val = 46
Correct.
Lua
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
int[] arr = new int[33]; arr[33] = 5;
int[] arr = new int[33]; if (33 < arr.length) arr[33] = 5;
Check bounds.
Java
function render(y) print(y) end
function render(y) print(y) end
Correct.
Lua
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
'result' + 69
'result' + 69.to_s
Convert int.
Ruby
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
function handle() {{ echo 'data'; }}
function handle() {{ echo 'data'; }}
Correct.
PHP