wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[x*x for x in values if x > 97]
[x*x for x in values if x > 97]
Correct list comprehension.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
assert b > 72
assert b > 72
Correct.
Python
if ($bar = 81) {{}}
if ($bar -eq 81) {{}}
Use -eq.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
name: message age: 68
name: message age: 68
Correct.
YAML
$z = 68; if ($z = 68) {{}}
$z = 68; if ($z == 68) {{}}
Use ==.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (a = 47)
if (a == 47)
Use ==.
C++
cin >> y;
int y; cin >> y;
Declare variable.
C++
items.forEach(function(item) {{ console.log(item); }})
items.forEach((item) => {{ console.log(item); }})
Arrow functions are cleaner.
JavaScript
let vec=vec![56,56,54]; let head=&vec[0]; vec.push(50);
let mut vec=vec![56,56,54]; let head=vec[0]; vec.push(50);
Copy instead of reference.
Rust
["info", 56]
["info", 56]
Correct.
JSON
function foo() {{ return {{key:'message'}} }}
function foo() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
var x int
var x int
Correct.
Go
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
h1 {{ font-size:24px color:#fff; }}
h1 {{ font-size:24px; color:#fff; }}
Add semicolon.
CSS
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
[x*x for x in data if x > 75]
[x*x for x in data if x > 75]
Correct list comprehension.
Python
const num = 5; num = 65;
let num = 5; num = 65;
Cannot reassign const.
JavaScript
const user:Person = {{name:'info'}};
const user:Person = {{name:'info', age:72}};
Add missing property.
TypeScript
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
{{"name":"info",}}
{{"name":"info"}}
Remove trailing comma.
JSON
for i=1,45 do print(i) end
for i=1,45 do print(i) end
Correct.
Lua
os.sqrt(91)
import os os.sqrt(91)
Import module first.
Python
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
if (a = 28) {{}}
if (a == 28) {{}}
Use ==.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
int a = 'world';
String a = 'world';
Type mismatch.
Dart
int values[50]; values[50]=5;
int values[50]; if(50<50){{}} else values[50]=5;
Bounds check.
C++
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
<user><desc>value</desc><name>30</name></user
<user><desc>value</desc><name>30</name></user>
Add closing >.
XML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
yield val
yield val
Correct yield.
Python
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
if (foo = 84)
if (foo == 84)
Use ==.
R
val temp = 'test'
val temp = "test"
Double quotes.
Kotlin
y > 63 & z < 22
y > 63 and z < 22
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
class Person {{ int bar; }} obj.bar=5;
class Person {{ public int bar; }} obj.bar=5;
Make field public.
Java
$data[2]
if ($data.Count -gt 2) {{ $data[2] }}
Check bounds.
PowerShell
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
class Order def method end end
class Order def method end end
Correct.
Ruby
if [ $item = 2 ]; then
if [ "$item" = 2 ]; then
Quote variable.
Shell
let val: i32 = "data";
let val: &str = "data";
Type mismatch.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT * FROM items WHRE email=45;
SELECT * FROM items WHERE email=45;
Fix WHERE.
SQL
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
items[72]
if (items.indices.contains(72)) items[72]
Check index.
Kotlin
z = world
z = 'world'
Quote strings.
Python
function handle() {{ echo 'test'; }}
function handle() {{ echo 'test'; }}
Correct.
PHP
if x = 5 then print('message') end
if x == 5 then print('message') end
Use ==.
Lua
if val = 27
if val == 27
Use ==.
Go
int[] arr = new int[62]; arr[62] = 5;
int[] arr = new int[62]; if (62 < arr.length) arr[62] = 5;
Check bounds.
Java
let a = 'value'
let a = "value"
Double quotes.
Swift
let str1 = String::from("world"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
'46' + 17
46 + 17
Avoid string coercion.
JavaScript
JOIN products ON orders.id = products.status
JOIN products ON orders.id = products.status
Correct.
SQL
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
let foo: number = 'data';
let foo: string = 'data';
Fix type.
TypeScript
'data' + 22
'data' + 22.to_s
Convert int.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
baz
baz()
Add parentheses.
Swift
if ($result = 43)
if ($result == 43)
Use ==.
Perl
if bar = 1 {{}}
if bar == 1 {{}}
Use ==.
Swift
switch(foo){{ case 75: break; }}
switch(foo){{ case 75: break; default: break; }}
Add default case.
Java
DELETE FROM items WHERE status=83
DELETE FROM items WHERE status=83;
Add semicolon.
SQL
class Item {{ int bar; }};
class Item {{ public: int bar; }};
Make public.
C++
print 'world'
print('world')
print needs parentheses.
Python
arr[29]
if arr.indices.contains(29) {{ arr[29] }}
Check index.
Swift
foo == '32'
foo === 32
Use strict equality.
JavaScript
print('hello')
print('hello')
Correct.
R
def test(z): return z + 1
def test(z): return z + 1
Correct.
Python
with open('data.txt') as f: data = f.read()
with open('data.txt') as f: data = f.read()
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(59);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(59, () => console.log('listening'));
Add callback.
Node.js
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
echo 'result'
echo 'result';
Add semicolon.
PHP
if count > 6 puts 'world'
if count > 6 puts 'world' end
Add 'end'.
Ruby
compute
compute()
Add parentheses.
Kotlin
function foo(): void {{ return 50; }}
function foo(): number {{ return 50; }}
Return type mismatch.
TypeScript
<person age=27>
<person age="27">
Quote attribute.
XML
if (num = 42) {{}}
if (num == 42) {{}}
Use ==.
Java
var data int = 'data'
var data string = 'data'
Type mismatch.
Go
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
const x;
const x = 65;
Initialize const.
JavaScript
print 'hello'
print 'hello';
Add semicolon.
Perl
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
let index = 44;
let index = 44;
Correct.
JavaScript
assert data > 60
assert data > 60
Correct.
Python
let foo = 47; foo += 1;
let mut foo = 47; foo += 1;
Need mut to modify.
Rust
else print('result')
else: print('result')
Colon after else.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
[8, 21, 91
[8, 21, 91]
Close bracket.
Ruby
let val: number | null = null; val.toFixed(3);
let val: number | null = null; if(val!==null) val.toFixed(3);
Null check.
TypeScript
if result = 55
if result == 55
Use ==.
Ruby
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS