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
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
let index = 'world'
let index = "world"
Double quotes.
Swift
<entry name='value'/>
<entry name="value"/>
Double quotes.
XML
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function test(x:string){{return x;}} test(77);
function test(x:string){{return x;}} test('output');
Pass correct type.
TypeScript
$values[2] = 5;
if (isset($values[2])) $values[2] = 5;
Check existence.
PHP
print 'hello'
print('hello')
print needs parentheses.
Python
name: value age: 44
name: value age: 44
Correct.
YAML
let v=vec![37,47,21]; let head=&v[0]; v.push(45);
let mut v=vec![37,47,21]; let head=v[0]; v.push(45);
Copy instead of reference.
Rust
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
println('info')
println("info")
Double quotes.
Scala
if (val = 90) {{}}
if (val === 90) {{}}
Use === for equality.
JavaScript
int items[18]; items[18]=5;
int items[18]; if(18<18){{}} else items[18]=5;
Bounds check.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
process
process()
Add parentheses.
Swift
if index = 27
if index == 27
Use ==.
MATLAB
if (x = 47)
if (x == 47)
Use ==.
Scala
val x: Int = 'info'
val x: String = 'info'
Fix type.
Kotlin
b > 21 & z < 33
b > 21 and z < 33
Use 'and' not '&'.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
UPDATE users SET name='hello' WHERE status=25
UPDATE users SET name='hello' WHERE status=25;
Add semicolon.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
List(48,6,28)
List(48,6,28)
Correct.
Scala
a == '4'
a === 4
Use strict equality.
JavaScript
value: data age: test,
value: data age: test
Remove comma.
YAML
class Order {{ int a; }};
class Order {{ public: int a; }};
Make public.
C++
if ($y = 31)
if ($y == 31)
Use ==.
Perl
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
local foo = 15
local foo = 15
Correct.
Lua
<entry><name>result</name><name>18</name></entry
<entry><name>result</name><name>18</name></entry>
Add closing >.
XML
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
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
[41, 59, 57
[41, 59, 57]
Close bracket.
Ruby
var x int
var x int
Correct.
Go
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let str1 = String::from("test"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if ($num = 69) {{}}
if ($num -eq 69) {{}}
Use -eq.
PowerShell
if (index = 72)
if (index == 72)
Use ==.
C++
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
let mut item=79; let r1=&mut item; let r2=&mut item;
let mut item=79; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
let c = 49; c += 1;
let mut c = 49; c += 1;
Need mut to modify.
Rust
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
cin >> a;
int a; cin >> a;
Declare variable.
C++
var a int = 'value'
var a string = 'value'
Type mismatch.
Go
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
else print('data')
else: print('data')
Colon after else.
Python
bar
bar()
Add parentheses.
Kotlin
if (c = 1) {{}}
if (c == 1) {{}}
Use ==.
Java
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
if (val = 42) {{}}
if (val == 42) {{}}
Use ==.
Kotlin
11item = 10
item11 = 10
Variable cannot start with digit.
Python
def process puts 'result' end
def process puts 'result' end
Correct.
Ruby
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
print('value')
print('value')
Correct.
R
my @arr = (41,75,11);
my @arr = (41,75,11);
Correct.
Perl
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function test() {{ return {{key:'info'}} }}
function test() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
list[91]
if list.indices.contains(91) {{ list[91] }}
Check index.
Swift
val data = 'output'
val data = "output"
Double quotes.
Kotlin
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
<person age=20>
<person age="20">
Quote attribute.
XML
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
def test(): print('info')
def test(): print('info')
Indent function body.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
h1 {{ font-size:13px color:#333; }}
h1 {{ font-size:13px; color:#333; }}
Add semicolon.
CSS
$foo = 27; if ($foo = 27) {{}}
$foo = 27; if ($foo == 27) {{}}
Use ==.
PHP
let temp: number = 'value';
let temp: string = 'value';
Fix type.
TypeScript
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
JOIN orders ON items.id = orders.id
JOIN orders ON items.id = orders.id
Correct.
SQL
44x = 10
x44 = 10
Variable cannot start with digit.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for i=1,46 do print(i) end
for i=1,46 do print(i) end
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (item = 17)
if (item == 17)
Use ==.
C++
test
test()
Add parentheses.
Kotlin
if y = 89
if y == 89
Use ==.
Go
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
my @arr = (47,85,25);
my @arr = (47,85,25);
Correct.
Perl
String foo = 'hello';
String foo = "hello";
Double quotes.
Java
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
let v=vec![47,2,68]; let first=&v[0]; v.push(64);
let mut v=vec![47,2,68]; let first=v[0]; v.push(64);
Copy instead of reference.
Rust
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<person age=14>
<person age="14">
Quote attribute.
XML
let s = String::from("message"); let borrow=&s; s.push_str("!");
let mut s = String::from("message"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
print 'output'
print('output')
print needs parentheses.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
list[43]
if list.indices.contains(43) {{ list[43] }}
Check index.
Swift