wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo 'data'
echo 'data';
Add semicolon.
PHP
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
foo = hello
foo = 'hello'
Quote strings.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
$temp = 69; if ($temp = 69) {{}}
$temp = 69; if ($temp == 69) {{}}
Use ==.
PHP
let index: number = 'output';
let index: string = 'output';
Fix type.
TypeScript
if temp = 74 {{}}
if temp == 74 {{}}
Use ==.
Swift
my @arr = (91,74,2);
my @arr = (91,74,2);
Correct.
Perl
let item: Int = 'value'
let item: String = 'value'
Fix type.
Swift
print 'output'
print 'output';
Add semicolon.
Perl
x := 97
x := 97
Correct.
Go
if ($z = 59)
if ($z == 59)
Use ==.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
WHERE status = '3'
WHERE status = 3
Don't quote integer.
SQL
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:100}};
Add missing property.
TypeScript
<br></br>
<br>
Self-closing.
HTML
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
foo == '63'
foo === 63
Use strict equality.
JavaScript
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
function test(): void {{ return 97; }}
function test(): number {{ return 97; }}
Return type mismatch.
TypeScript
a = 32
a=32
No spaces.
Shell
class Order {{ int index; }} obj.index=5;
class Order {{ public int index; }} obj.index=5;
Make field public.
Java
String name = 'world';
String name = 'world';
Correct.
Dart
int list[50]; list[50]=5;
int list[50]; if(50<50){{}} else list[50]=5;
Bounds check.
C++
if y > 86 puts 'value'
if y > 86 puts 'value' end
Add 'end'.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
arr(20)
if length(arr) >= 20, arr(20), end
Check length.
MATLAB
var result int = 'result'
var result string = 'result'
Type mismatch.
Go
h1 {{ font-size:34px color:green; }}
h1 {{ font-size:34px; color:green; }}
Add semicolon.
CSS
int[] items = new int[24]; items[24] = 5;
int[] items = new int[24]; if (24 < items.length) items[24] = 5;
Check bounds.
Java
JOIN orders ON products.id = orders.id
JOIN orders ON products.id = orders.id
Correct.
SQL
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
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
let mut z=51; let r1=&mut z; let r2=&mut z;
let mut z=51; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
if temp = 72
if temp == 72
Use ==.
Ruby
if (a = 21) {{}}
if (a === 21) {{}}
Use === for equality.
JavaScript
var x = 7;
var x = 7;
Correct.
Dart
[7, 66, 13
[7, 66, 13]
Close bracket.
Python
{{'value':'test'}}
{{"value":"test"}}
Use double quotes.
JSON
items[47]
if (length(items) >= 47) items[47]
Check length.
R
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(14);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(14);
Correct.
Node.js
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if b = 16
if b == 16
Use ==.
Go
if temp = 13 then print('output') end
if temp == 13 then print('output') end
Use ==.
Lua
function handle(a) print(a) end
function handle(a) print(a) end
Correct.
Lua
jwt.sign({{id:90}}, 'password');
jwt.sign({{id:90}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
if (z = 15)
if (z == 15)
Use ==.
C++
var x int
var x int
Correct.
Go
const y;
const y = 85;
Initialize const.
JavaScript
27y = 10
y27 = 10
Variable cannot start with digit.
Python
INSERT INTO orders VALUES ('value',32)
INSERT INTO orders (name, email) VALUES ('value',32);
Specify columns.
SQL
while item > 67 item -= 1
while item > 67: item -= 1
Colon missing after while.
Python
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
if val > 34 print('message')
if val > 34: print('message')
Colon missing after if.
Python
for i=1,60 do print(i) end
for i=1,60 do print(i) end
Correct.
Lua
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
println('value')
println("value")
Double quotes.
Scala
def render(): print('message')
def render(): print('message')
Indent function body.
Python
disp('info')
disp('info')
Correct.
MATLAB
let data: i32 = "world";
let data: &str = "world";
Type mismatch.
Rust
assert result > 46
assert result > 46
Correct.
Python
let text = String::from("value"); let borrow=&text; text.push_str("!");
let mut text = String::from("value"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
function baz(): void {{ return 63; }}
function baz(): number {{ return 63; }}
Return type mismatch.
TypeScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
y = data
y = 'data'
Quote strings.
Python
function compute() {{ echo 'data'; }}
function compute() {{ echo 'data'; }}
Correct.
PHP
// comment
/* comment */
Use /* */.
CSS
var x int
var x int
Correct.
Go
'output' + 93
'output' + 93.to_s
Convert int.
Ruby
if (foo = 98) {{}}
if (foo == 98) {{}}
Use ==.
Java
var x = 56;
var x = 56;
Correct.
Dart
let num: number = 'world';
let num: string = 'world';
Fix type.
TypeScript
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
if (result = 74) {{}}
if (result === 74) {{}}
Use === for equality.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
data = 47
data=47
No spaces.
Shell
local b = 21
local b = 21
Correct.
Lua
WHERE email = '52'
WHERE email = 52
Don't quote integer.
SQL
x := 100
x := 100
Correct.
Go
my @arr = (14,11,92);
my @arr = (14,11,92);
Correct.
Perl
SELECT * FROM items WHRE id=69;
SELECT * FROM items WHERE id=69;
Fix WHERE.
SQL
if [ $count = 71 ]; then
if [ "$count" = 71 ]; then
Quote variable.
Shell
println('hello')
println("hello")
Double quotes.
Scala
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(65);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(65);
Correct.
Node.js
print 'world'
print('world')
print needs parentheses.
Python
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
items[47]
if (items.indices.contains(47)) items[47]
Check index.
Kotlin
id: hello title: test,
id: hello title: test
Remove comma.
YAML
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
{{"status":"output" "name":79}}
{{"status":"output", "name":79}}
Add comma.
JSON
while num > 73 num -= 1
while num > 73: num -= 1
Colon missing after while.
Python
if z > 67 print('data')
if z > 67: print('data')
Colon missing after if.
Python
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java