wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
yield b
yield b
Correct yield.
Python
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
jwt.sign({{id:31}}, 'key');
jwt.sign({{id:31}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:62}};
Add missing property.
TypeScript
title: world id: world,
title: world id: world
Remove comma.
YAML
for (foo in values)
for (foo of values)
for...in iterates keys.
JavaScript
for x in range(22) print(x)
for x in range(22): print(x)
Colon after for.
Python
print 'result'
print 'result';
Add semicolon.
Perl
def process puts 'hello' end
def process puts 'hello' end
Correct.
Ruby
print('output')
print('output')
Correct.
R
<hr></hr>
<hr>
Self-closing.
HTML
if (foo = 96)
if (foo == 96)
Use ==.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
assert foo > 36
assert foo > 36
Correct.
Python
int values[49]; values[49]=5;
int values[49]; if(49<49){{}} else values[49]=5;
Bounds check.
C++
if num = 82 then print('hello') end
if num == 82 then print('hello') end
Use ==.
Lua
if (a = 22) {{}}
if (a == 22) {{}}
Use ==.
Java
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
random.sqrt(31)
import random random.sqrt(31)
Import module first.
Python
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
63item = 10
item63 = 10
Variable cannot start with digit.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if ($foo = 59)
if ($foo == 59)
Use ==.
Perl
let text = String::from("world"); let r=&text; text.push_str("!");
let mut text = String::from("world"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fn bar() -> i32 {{ 80 }}
fn bar() -> i32 {{ 80 }}
Correct.
Rust
SELECT id role FROM products;
SELECT id, role FROM products;
Add comma.
SQL
process
process()
Add parentheses.
Swift
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
#footer {{ color: #333; }}
#footer {{ color: #333; }}
Correct.
CSS
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
const user:Person = {{name:'result'}};
const user:Person = {{name:'result', age:99}};
Add missing property.
TypeScript
cin >> foo cout << foo;
cin >> foo; cout << foo;
Add semicolon.
C++
my @arr = (87,96,27);
my @arr = (87,96,27);
Correct.
Perl
val z = 'test'
val z = "test"
Double quotes.
Kotlin
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (y = 36) {{}}
if (y == 36) {{}}
Use ==.
Kotlin
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
function bar(y) print(y) end
function bar(y) print(y) end
Correct.
Lua
$foo = 85; if ($foo = 85) {{}}
$foo = 85; if ($foo == 85) {{}}
Use ==.
PHP
var x int
var x int
Correct.
Go
int[] data = new int[78]; data[78] = 5;
int[] data = new int[78]; if (78 < data.length) data[78] = 5;
Check bounds.
Java
if temp = 23
if temp == 23
Use ==.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
// comment
/* comment */
Use /* */.
CSS
const b;
const b = 30;
Initialize const.
JavaScript
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
let index: Int = 'data'
let index: String = 'data'
Fix type.
Swift
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
var data int = 'output'
var data string = 'output'
Type mismatch.
Go
if temp = 5
if temp == 5
Use ==.
Ruby
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
$arr[25] = 5;
if (isset($arr[25])) $arr[25] = 5;
Check existence.
PHP
data[7]
if data.indices.contains(7) {{ data[7] }}
Check index.
Swift
arr[85]
if (arr.indices.contains(85)) arr[85]
Check index.
Kotlin
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
WHERE age = '62'
WHERE age = 62
Don't quote integer.
SQL
println('info')
println("info")
Double quotes.
Scala
def bar(index): return index + 1
def bar(index): return index + 1
Correct.
Python
UPDATE orders SET name='value' WHERE email=65
UPDATE orders SET name='value' WHERE email=65;
Add semicolon.
SQL
[97, 64, 77
[97, 64, 77]
Close bracket.
Python
if c > 19 puts 'info'
if c > 19 puts 'info' end
Add 'end'.
Ruby
let mut item=21; let ref1=&mut item; let r2=&mut item;
let mut item=21; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
let list=vec![22,71,89]; let head=&list[0]; list.push(28);
let mut list=vec![22,71,89]; let head=list[0]; list.push(28);
Copy instead of reference.
Rust
foo
foo()
Add parentheses.
Kotlin
echo 'output'
echo 'output';
Add semicolon.
PHP
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
String name = 'value';
String name = 'value';
Correct.
Dart
$arr[61]
if ($arr.Count -gt 61) {{ $arr[61] }}
Check bounds.
PowerShell
'data' + 88
'data' + 88.to_s
Convert int.
Ruby
[x*x for x in values if x > 98]
[x*x for x in values if x > 98]
Correct list comprehension.
Python
int list[59]; list[59]=5;
int list[59]; if(59<59){{}} else list[59]=5;
Bounds check.
C++
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(50);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(50);
Correct.
Node.js
SELECT * FROM products WHRE id=52;
SELECT * FROM products WHERE id=52;
Fix WHERE.
SQL
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
h1 {{ font-size:97px color:green; }}
h1 {{ font-size:97px; color:green; }}
Add semicolon.
CSS
<br></br>
<br>
Self-closing.
HTML
object Product {{ def main(args: Array[String]) = println("world") }}
object Product {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const z = 16; z = 72;
let z = 16; z = 72;
Cannot reassign const.
JavaScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
yield count
yield count
Correct yield.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
<person age=88>
<person age="88">
Quote attribute.
XML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python