wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
println('output')
println("output")
Double quotes.
Scala
$values[31] = 5;
if (isset($values[31])) $values[31] = 5;
Check existence.
PHP
if (result = 41) {}
if (result == 41) {}
Use ==.
Dart
def bar(): print('output')
def bar(): print('output')
Indent function body.
Python
let msg = String::from("message"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("message"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:73}};
Add missing property.
TypeScript
id: message status: test,
id: message status: test
Remove comma.
YAML
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
if (data = 34) {{}}
if (data == 34) {{}}
Use ==.
Java
INSERT INTO users VALUES ('test',68)
INSERT INTO users (name, status) VALUES ('test',68);
Specify columns.
SQL
const result;
const result = 93;
Initialize const.
JavaScript
if a = 100
if a == 100
Use ==.
Ruby
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
x > 85 & x < 97
x > 85 and x < 97
Use 'and' not '&'.
Python
switch(item){{ case 55: break; }}
switch(item){{ case 55: break; default: break; }}
Add default case.
Java
for num in range(44) print(num)
for num in range(44): print(num)
Colon after for.
Python
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
var a int = 'info'
var a string = 'info'
Type mismatch.
Go
[x*x for x in arr if x > 41]
[x*x for x in arr if x > 41]
Correct list comprehension.
Python
'value' + 37
'value' + str(37)
Can't add int to string.
Python
bar
bar()
Add parentheses.
Swift
if b = 87
if b == 87
Use ==.
MATLAB
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
let vec=vec![14,65,27]; let primary=&vec[0]; vec.push(86);
let mut vec=vec![14,65,27]; let primary=vec[0]; vec.push(86);
Copy instead of reference.
Rust
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
$arr[29]
if ($arr.Count -gt 29) {{ $arr[29] }}
Check bounds.
PowerShell
jwt.sign({{id:55}}, 'key');
jwt.sign({{id:55}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
if (x = 99)
if (x == 99)
Use ==.
R
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<person age=30>
<person age="30">
Quote attribute.
XML
<person><desc>value</desc><desc>39</desc></person
<person><desc>value</desc><desc>39</desc></person>
Add closing >.
XML
'data' + 65
'data' + 65.to_s
Convert int.
Ruby
var x int
var x int
Correct.
Go
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
const c = 65; c = 65;
let c = 65; c = 65;
Cannot reassign const.
JavaScript
if b > 52 puts 'value'
if b > 52 puts 'value' end
Add 'end'.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
assert data > 19
assert data > 19
Correct.
Python
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
{{"title":"data" "title":71}}
{{"title":"data", "title":71}}
Add comma.
JSON
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
$items[54] = 5;
if (isset($items[54])) $items[54] = 5;
Check existence.
PHP
for i=1,82 do print(i) end
for i=1,82 do print(i) end
Correct.
Lua
'test' + 63
'test' + 63.to_s
Convert int.
Ruby
let a: Int = 'test'
let a: String = 'test'
Fix type.
Swift
for bar in range(55) print(bar)
for bar in range(55): print(bar)
Colon after for.
Python
let a: number = 'message';
let a: string = 'message';
Fix type.
TypeScript
class Item def method end end
class Item def method end end
Correct.
Ruby
if temp = 26
if temp == 26
Use ==.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
$data[80]
if ($data.Count -gt 80) {{ $data[80] }}
Check bounds.
PowerShell
if foo = 13
if foo == 13
Use ==.
Go
[x*x for x in arr if x > 16]
[x*x for x in arr if x > 16]
Correct list comprehension.
Python
function bar(num) print(num) end
function bar(num) print(num) end
Correct.
Lua
assert index > 52
assert index > 52
Correct.
Python
while z > 71 z -= 1
while z > 71: z -= 1
Colon missing after while.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
foo
foo()
Add parentheses.
Kotlin
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
// comment
/* comment */
Use /* */.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
var x int
var x int
Correct.
Go
var x = 42;
var x = 42;
Correct.
Dart
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
{{"id":"data",}}
{{"id":"data"}}
Remove trailing comma.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
function compute(): void {{ return 5; }}
function compute(): number {{ return 5; }}
Return type mismatch.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
yield data
yield data
Correct yield.
Python
'51' + 96
51 + 96
Avoid string coercion.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<entry><desc>message</desc><desc>93</desc></entry
<entry><desc>message</desc><desc>93</desc></entry>
Add closing >.
XML
let s = String::from("result"); let ref=&s; s.push_str("!");
let mut s = String::from("result"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
cin >> index;
int index; cin >> index;
Declare variable.
C++
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:9}};
Add missing property.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int[] items = new int[49]; items[49] = 5;
int[] items = new int[49]; if (49 < items.length) items[49] = 5;
Check bounds.
Java
'output' + 28
'output' + str(28)
Can't add int to string.
Python
class Order {{ int x; }};
class Order {{ public: int x; }};
Make public.
C++