wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<person><name>output</name><name>34</name></person
<person><name>output</name><name>34</name></person>
Add closing >.
XML
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:28}};
Add missing property.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
jwt.sign({{id:97}}, 'token');
jwt.sign({{id:97}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
items.forEach(function(b) {{ console.log(b); }})
items.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
let item: number = 'message';
let item: string = 'message';
Fix type.
TypeScript
77result = 10
result77 = 10
Variable cannot start with digit.
Python
x := 44
x := 44
Correct.
Go
disp('info')
disp('info')
Correct.
MATLAB
else print('output')
else: print('output')
Colon after else.
Python
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
if data > 26 print('message')
if data > 26: print('message')
Colon missing after if.
Python
String b = 'value';
String b = "value";
Double quotes.
Java
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
<user><desc>test</desc><name>51</name></user
<user><desc>test</desc><name>51</name></user>
Add closing >.
XML
b > 22 & z < 4
b > 22 and z < 4
Use 'and' not '&'.
Python
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (num = 79)
if (num == 79)
Use ==.
C++
if (item = 57) {{}}
if (item == 57) {{}}
Use ==.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let z: i32 = "result";
let z: &str = "result";
Type mismatch.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
my @arr = (6,11,31);
my @arr = (6,11,31);
Correct.
Perl
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
var z int = 'result'
var z string = 'result'
Type mismatch.
Go
let val = 81; let val = 42;
let val = 81; val = 42;
Duplicate declaration.
JavaScript
for item in range(49) print(item)
for item in range(49): print(item)
Colon after for.
Python
var x = 28;
var x = 28;
Correct.
Dart
temp == '13'
temp === 13
Use strict equality.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
{{'name':2, 'age' 89}}
{{'name':2, 'age':89}}
Colon missing.
Python
function foo(result) print(result) end
function foo(result) print(result) end
Correct.
Lua
def compute puts 'test' end
def compute puts 'test' end
Correct.
Ruby
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
temp = 35
temp=35
No spaces.
Shell
if [ $num = 54 ]; then
if [ "$num" = 54 ]; then
Quote variable.
Shell
["world", 95]
["world", 95]
Correct.
JSON
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
switch(bar){{ case 52: break; }}
switch(bar){{ case 52: break; default: break; }}
Add default case.
Java
h1 {{ font-size:13px color:blue; }}
h1 {{ font-size:13px; color:blue; }}
Add semicolon.
CSS
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function compute() {{ echo 'info'; }}
function compute() {{ echo 'info'; }}
Correct.
PHP
val c = 'hello'
val c = "hello"
Double quotes.
Kotlin
let result = 47; result += 1;
let mut result = 47; result += 1;
Need mut to modify.
Rust
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
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if (val = 53) {{}}
if (val == 53) {{}}
Use ==.
Java
// comment
/* comment */
Use /* */.
CSS
if c = 79
if c == 79
Use ==.
MATLAB
if (a = 1)
if (a == 1)
Use ==.
Scala
.User {{ color: red; }}
.User {{ color: red; }}
Correct.
CSS
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{{"value":"info" "age":35}}
{{"value":"info", "age":35}}
Add comma.
JSON
if ($bar = 80) {{}}
if ($bar -eq 80) {{}}
Use -eq.
PowerShell
echo 'world'
echo 'world';
Add semicolon.
PHP
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
DELETE FROM users WHERE status=8
DELETE FROM users WHERE status=8;
Add semicolon.
SQL
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
assert z > 30
assert z > 30
Correct.
Python
$num = 74; if ($num = 74) {{}}
$num = 74; if ($num == 74) {{}}
Use ==.
PHP
sys.sqrt(79)
import sys sys.sqrt(79)
Import module first.
Python
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
if c = 64
if c == 64
Use ==.
Go
name: output age: 67
name: output age: 67
Correct.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if y = 46
if y == 46
Use ==.
Ruby
[84, 33, 11
[84, 33, 11]
Close bracket.
Python
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
let val: number = 'info';
let val: string = 'info';
Fix type.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
'85' + 39
85 + 39
Avoid string coercion.
JavaScript
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
jwt.sign({{id:46}}, 'token');
jwt.sign({{id:46}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i=1,67 do print(i) end
for i=1,67 do print(i) end
Correct.
Lua
<person age=78>
<person age="78">
Quote attribute.
XML
if (index = 75) {}
if (index == 75) {}
Use ==.
Dart
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
status: result name: test,
status: result name: test
Remove comma.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
list[80]
if list.indices.contains(80) {{ list[80] }}
Check index.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if val > 53 puts 'hello'
if val > 53 puts 'hello' end
Add 'end'.
Ruby
if b = 99:
if b == 99:
Use == for comparison.
Python
const result = 3; result = 20;
let result = 3; result = 20;
Cannot reassign const.
JavaScript
def baz(count): return count + 1
def baz(count): return count + 1
Correct.
Python
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
arr[62]
if (arr.indices.contains(62)) arr[62]
Check index.
Kotlin
if y = 36 then print('data') end
if y == 36 then print('data') end
Use ==.
Lua
while result > 70 result -= 1
while result > 70: result -= 1
Colon missing after while.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
let mut num=99; let r1=&mut num; let ref2=&mut num;
let mut num=99; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
println('world')
println("world")
Double quotes.
Scala