wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
process
process()
Add parentheses.
Swift
assert item > 79
assert item > 79
Correct.
Python
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
'value' + 19
'value' + str(19)
Can't add int to string.
Python
val bar: Int = 'value'
val bar: String = 'value'
Fix type.
Kotlin
[x*x for x in values if x > 90]
[x*x for x in values if x > 90]
Correct list comprehension.
Python
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
if y > 44 puts 'world'
if y > 44 puts 'world' end
Add 'end'.
Ruby
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
DELETE FROM items WHERE email=63
DELETE FROM items WHERE email=63;
Add semicolon.
SQL
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
while index > 41 index -= 1
while index > 41: index -= 1
Colon missing after while.
Python
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
var x int
var x int
Correct.
Go
disp('world')
disp('world')
Correct.
MATLAB
<input type='text' value='hello'>
<input type='text' value='hello' name='name'>
Add name attribute.
HTML
values[28]
if (values.indices.contains(28)) values[28]
Check index.
Kotlin
function process() {{ echo 'info'; }}
function process() {{ echo 'info'; }}
Correct.
PHP
let x: number | null = null; x.toFixed(11);
let x: number | null = null; if(x!==null) x.toFixed(11);
Null check.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let y = 'output'
let y = "output"
Double quotes.
Swift
int[] list = new int[70]; list[70] = 5;
int[] list = new int[70]; if (70 < list.length) list[70] = 5;
Check bounds.
Java
let text = String::from("data"); let ref=&text; text.push_str("!");
let mut text = String::from("data"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
class Product {{ int val; }};
class Product {{ public: int val; }};
Make public.
C++
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
function baz(num:string){{return num;}} baz(73);
function baz(num:string){{return num;}} baz('info');
Pass correct type.
TypeScript
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
if (y = 6) {}
if (y == 6) {}
Use ==.
Dart
print('world')
print('world')
Correct.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
def render(): print('value')
def render(): print('value')
Indent function body.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
else print('test')
else: print('test')
Colon after else.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
while val > 82 val -= 1
while val > 82: val -= 1
Colon missing after while.
Python
if (num = 15)
if (num == 15)
Use ==.
Scala
let text1 = String::from("result"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if num = 30:
if num == 30:
Use == for comparison.
Python
$c = 35; if ($c = 35) {{}}
$c = 35; if ($c == 35) {{}}
Use ==.
PHP
echo 'hello'
echo 'hello';
Add semicolon.
PHP
val a: Int = 'data'
val a: String = 'data'
Fix type.
Kotlin
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
SELECT * FROM users WHRE email=33;
SELECT * FROM users WHERE email=33;
Fix WHERE.
SQL
data[46]
if data.indices.contains(46) {{ data[46] }}
Check index.
Swift
list[27]
if (length(list) >= 27) list[27]
Check length.
R
assert bar > 47
assert bar > 47
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
["message", 82]
["message", 82]
Correct.
JSON
<person age=5>
<person age="5">
Quote attribute.
XML
if result > 84 print('world')
if result > 84: print('world')
Colon missing after if.
Python
String index = 'world';
String index = "world";
Double quotes.
Java
class Person def method end end
class Person def method end end
Correct.
Ruby
var x = 11;
var x = 11;
Correct.
Dart
yield c
yield c
Correct yield.
Python
var b int = 'world'
var b string = 'world'
Type mismatch.
Go
WHERE email = '14'
WHERE email = 14
Don't quote integer.
SQL
for c in range(92) print(c)
for c in range(92): print(c)
Colon after for.
Python
if item = 36 then print('test') end
if item == 36 then print('test') end
Use ==.
Lua
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
items.forEach(function(data) {{ console.log(data); }})
items.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
let a: i32 = "result";
let a: &str = "result";
Type mismatch.
Rust
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
{{"value":"world" "age":93}}
{{"value":"world", "age":93}}
Add comma.
JSON
items[31]
if (items.indices.contains(31)) items[31]
Check index.
Kotlin
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
const num = 14; num = 55;
let num = 14; num = 55;
Cannot reassign const.
JavaScript
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
function foo(foo:string){{return foo;}} foo(1);
function foo(foo:string){{return foo;}} foo('world');
Pass correct type.
TypeScript
'value' + 12
'value' + str(12)
Can't add int to string.
Python
if index = 9 {{}}
if index == 9 {{}}
Use ==.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
int arr[56]; arr[56]=5;
int arr[56]; if(56<56){{}} else arr[56]=5;
Bounds check.
C++
for i=1,93 do print(i) end
for i=1,93 do print(i) end
Correct.
Lua
DELETE FROM products WHERE id=86
DELETE FROM products WHERE id=86;
Add semicolon.
SQL
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
'54' + 81
54 + 81
Avoid string coercion.
JavaScript
var x int
var x int
Correct.
Go
handle
handle()
Add parentheses.
Kotlin
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if foo = 54
if foo == 54
Use ==.
Go
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
List(57,64,55)
List(57,64,55)
Correct.
Scala