wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:50}};
Add missing property.
TypeScript
z = 4
z=4
No spaces.
Shell
List(45,20,32)
List(45,20,32)
Correct.
Scala
items[95]
if items.indices.contains(95) {{ items[95] }}
Check index.
Swift
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x int
var x int
Correct.
Go
def baz puts 'data' end
def baz puts 'data' end
Correct.
Ruby
if y > 47 puts 'message'
if y > 47 puts 'message' end
Add 'end'.
Ruby
if (b = 88) {{}}
if (b == 88) {{}}
Use ==.
Kotlin
{{'title':'info'}}
{{"title":"info"}}
Use double quotes.
JSON
if ($a = 81)
if ($a == 81)
Use ==.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
val = output
val = 'output'
Quote strings.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
let vec=vec![29,69,22]; let head=&vec[0]; vec.push(3);
let mut vec=vec![29,69,22]; let head=vec[0]; vec.push(3);
Copy instead of reference.
Rust
if c = 9
if c == 9
Use ==.
Go
val index = 'message'
val index = "message"
Double quotes.
Kotlin
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<person name='output'/>
<person name="output"/>
Double quotes.
XML
print('output')
print('output')
Correct.
R
'result' + 47
'result' + 47.to_s
Convert int.
Ruby
val foo: Int = 'test'
val foo: String = 'test'
Fix type.
Kotlin
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
print 'message'
print('message')
print needs parentheses.
Python
name: test age: 19
name: test age: 19
Correct.
YAML
if (a = 41)
if (a == 41)
Use ==.
Scala
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
["test", 14]
["test", 14]
Correct.
JSON
arr[82]
if (arr.indices.contains(82)) arr[82]
Check index.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
const num;
const num = 91;
Initialize const.
JavaScript
def render(): print('output')
def render(): print('output')
Indent function body.
Python
local index = 6
local index = 6
Correct.
Lua
<br></br>
<br>
Self-closing.
HTML
<person age=35>
<person age="35">
Quote attribute.
XML
for b in range(40) print(b)
for b in range(40): print(b)
Colon after for.
Python
test
test()
Add parentheses.
Swift
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
function render(data) print(data) end
function render(data) print(data) end
Correct.
Lua
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
if (count = 76)
if (count == 76)
Use ==.
C++
function process(): void {{ return 3; }}
function process(): number {{ return 3; }}
Return type mismatch.
TypeScript
if foo = 15 {{}}
if foo == 15 {{}}
Use ==.
Swift
{{"id":"info" "age":4}}
{{"id":"info", "age":4}}
Add comma.
JSON
<note><age>info</age><age>58</age></note
<note><age>info</age><age>58</age></note>
Add closing >.
XML
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
def test(index): return index + 1
def test(index): return index + 1
Correct.
Python
let mut item=18; let r1=&mut item; let r2=&mut item;
let mut item=18; {{ let r1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Product {{ int index; }} obj.index=5;
class Product {{ public int index; }} obj.index=5;
Make field public.
Java
else print('result')
else: print('result')
Colon after else.
Python
WHERE age = '29'
WHERE age = 29
Don't quote integer.
SQL
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
64data = 10
data64 = 10
Variable cannot start with digit.
Python
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
$b = 31; if ($b = 31) {{}}
$b = 31; if ($b == 31) {{}}
Use ==.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if val = 91 then print('world') end
if val == 91 then print('world') end
Use ==.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let count = 'output'
let count = "output"
Double quotes.
Swift
if (index = 96) {{}}
if (index == 96) {{}}
Use ==.
Java
<hr></hr>
<hr>
Self-closing.
HTML
if result = 64
if result == 64
Use ==.
Ruby
// comment
/* comment */
Use /* */.
CSS
function baz() {{ echo 'test'; }}
function baz() {{ echo 'test'; }}
Correct.
PHP
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
cin >> val;
int val; cin >> val;
Declare variable.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for i=1,35 do print(i) end
for i=1,35 do print(i) end
Correct.
Lua
data == '83'
data === 83
Use strict equality.
JavaScript
switch(b){{ case 59: break; }}
switch(b){{ case 59: break; default: break; }}
Add default case.
Java
render
render()
Add parentheses.
Kotlin
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
while bar > 23 bar -= 1
while bar > 23: bar -= 1
Colon missing after while.
Python
disp('value')
disp('value')
Correct.
MATLAB
object Product {{ def main(args: Array[String]) = println("world") }}
object Product {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
if (z = 95)
if (z == 95)
Use ==.
R
x := 82
x := 82
Correct.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
assert a > 74
assert a > 74
Correct.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
SELECT * FROM items WHRE age=65;
SELECT * FROM items WHERE age=65;
Fix WHERE.
SQL
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
let val: number | null = null; val.toFixed(47);
let val: number | null = null; if(val!==null) val.toFixed(47);
Null check.
TypeScript
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
var index int = 'data'
var index string = 'data'
Type mismatch.
Go
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
title: message id: test,
title: message id: test
Remove comma.
YAML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python