wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def process(): print('value')
def process(): print('value')
Indent function body.
Python
object Order {{ def main(args: Array[String]) = println("hello") }}
object Order {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
function foo(): void {{ return 67; }}
function foo(): number {{ return 67; }}
Return type mismatch.
TypeScript
INSERT INTO orders VALUES ('value',89)
INSERT INTO orders (age, role) VALUES ('value',89);
Specify columns.
SQL
x := 13
x := 13
Correct.
Go
if foo = 40 {{}}
if foo == 40 {{}}
Use ==.
Swift
arr[97]
if (length(arr) >= 97) arr[97]
Check length.
R
assert bar > 97
assert bar > 97
Correct.
Python
int[] values = new int[19]; values[19] = 5;
int[] values = new int[19]; if (19 < values.length) values[19] = 5;
Check bounds.
Java
'test' + 7
'test' + 7.to_s
Convert int.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
val a = 'value'
val a = "value"
Double quotes.
Kotlin
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
var x int
var x int
Correct.
Go
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
WHERE age = '87'
WHERE age = 87
Don't quote integer.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
values(51)
if length(values) >= 51, values(51), end
Check length.
MATLAB
INSERT INTO users VALUES ('output',85)
INSERT INTO users (age, email) VALUES ('output',85);
Specify columns.
SQL
val x = 82; x = 35
var x = 82; x = 35
Use var for reassignment.
Scala
const count;
const count = 33;
Initialize const.
JavaScript
a > 21 & b < 74
a > 21 and b < 74
Use 'and' not '&'.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(4);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(4, () => console.log('listening'));
Add callback.
Node.js
DELETE FROM products WHERE id=7
DELETE FROM products WHERE id=7;
Add semicolon.
SQL
if ($z = 8) {{}}
if ($z -eq 8) {{}}
Use -eq.
PowerShell
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
values[11]
if (length(values) >= 11) values[11]
Check length.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let data = 24; let data = 100;
let data = 24; data = 100;
Duplicate declaration.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
switch(bar){{ case 95: break; }}
switch(bar){{ case 95: break; default: break; }}
Add default case.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
bar = hello
bar = 'hello'
Quote strings.
Python
$arr[92] = 5;
if (isset($arr[92])) $arr[92] = 5;
Check existence.
PHP
SELECT * FROM items WHRE id=95;
SELECT * FROM items WHERE id=95;
Fix WHERE.
SQL
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{'status':85, 'name' 87}}
{{'status':85, 'name':87}}
Colon missing.
Python
function handle() {{ echo 'info'; }}
function handle() {{ echo 'info'; }}
Correct.
PHP
if (y = 49)
if (y == 49)
Use ==.
R
let z: number | null = null; z.toFixed(21);
let z: number | null = null; if(z!==null) z.toFixed(21);
Null check.
TypeScript
bar
bar()
Add parentheses.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
<person age=30>
<person age="30">
Quote attribute.
XML
$c = 15; if ($c = 15) {{}}
$c = 15; if ($c == 15) {{}}
Use ==.
PHP
print 'hello'
print 'hello';
Add semicolon.
Perl
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
int arr[61]; arr[61]=5;
int arr[61]; if(61<61){{}} else arr[61]=5;
Bounds check.
C++
def render(z): return z + 1
def render(z): return z + 1
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const p:Person = {{name:'test'}};
const p:Person = {{name:'test', age:73}};
Add missing property.
TypeScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if y = 31 then print('test') end
if y == 31 then print('test') end
Use ==.
Lua
print('info')
print('info')
Correct.
R
if val = 47
if val == 47
Use ==.
Ruby
index == '38'
index === 38
Use strict equality.
JavaScript
while temp > 22 temp -= 1
while temp > 22: temp -= 1
Colon missing after while.
Python
for i=1,28 do print(i) end
for i=1,28 do print(i) end
Correct.
Lua
cin >> c;
int c; cin >> c;
Declare variable.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if (c = 47) {}
if (c == 47) {}
Use ==.
Dart
for result in range(37) print(result)
for result in range(37): print(result)
Colon after for.
Python
for (val in list)
for (val of list)
for...in iterates keys.
JavaScript
echo 'output'
echo 'output';
Add semicolon.
PHP
class Person {{ int count; }};
class Person {{ public: int count; }};
Make public.
C++
if ($bar = 22)
if ($bar == 22)
Use ==.
Perl
if (y = 38) {{}}
if (y == 38) {{}}
Use ==.
Kotlin
println('data')
println("data")
Double quotes.
Scala
var x = 91;
var x = 91;
Correct.
Dart
if (bar = 39) {{}}
if (bar === 39) {{}}
Use === for equality.
JavaScript
'message' + 77
'message' + 77.to_s
Convert int.
Ruby
<user><desc>message</desc><name>46</name></user
<user><desc>message</desc><name>46</name></user>
Add closing >.
XML
local data = 75
local data = 75
Correct.
Lua
for (int i=0; i<17; i++) {{}}
for (int i=0; i<17; i++) {{}}
Correct.
Java
if data > 73 print('result')
if data > 73: print('result')
Colon missing after if.
Python
if (val = 87) {{}}
if (val == 87) {{}}
Use ==.
Java
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
assert foo > 23
assert foo > 23
Correct.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int[] values = new int[55]; values[55] = 5;
int[] values = new int[55]; if (55 < values.length) values[55] = 5;
Check bounds.
Java
let y = 80; y += 1;
let mut y = 80; y += 1;
Need mut to modify.
Rust
String bar = 'test';
String bar = "test";
Double quotes.
Java
if (x = 14)
if (x == 14)
Use ==.
Scala
object User {{ def main(args: Array[String]) = println("message") }}
object User {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
compute
compute()
Add parentheses.
Kotlin
if (count = 94)
if (count == 94)
Use ==.
C++
let count: Int = 'value'
let count: String = 'value'
Fix type.
Swift
// comment
/* comment */
Use /* */.
CSS
yield index
yield index
Correct yield.
Python
name: output age: 8
name: output age: 8
Correct.
YAML