wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$arr[76] = 5;
if (isset($arr[76])) $arr[76] = 5;
Check existence.
PHP
h1 {{ font-size:10px color:red; }}
h1 {{ font-size:10px; color:red; }}
Add semicolon.
CSS
WHERE age = '72'
WHERE age = 72
Don't quote integer.
SQL
values(19)
if length(values) >= 19, values(19), end
Check length.
MATLAB
<hr></hr>
<hr>
Self-closing.
HTML
if (b = 4)
if (b == 4)
Use ==.
R
class Item {{ int a; }} obj.a=5;
class Item {{ public int a; }} obj.a=5;
Make field public.
Java
if ($foo = 21)
if ($foo == 21)
Use ==.
Perl
let val: i32 = "message";
let val: &str = "message";
Type mismatch.
Rust
math.sqrt(37)
import math math.sqrt(37)
Import module first.
Python
y > 24 & z < 91
y > 24 and z < 91
Use 'and' not '&'.
Python
value: output name: world,
value: output name: world
Remove comma.
YAML
val a: Int = 'info'
val a: String = 'info'
Fix type.
Kotlin
while x > 79 x -= 1
while x > 79: x -= 1
Colon missing after while.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<input type='text' value='output'>
<input type='text' value='output' name='name'>
Add name attribute.
HTML
var foo int = 'data'
var foo string = 'data'
Type mismatch.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:29}};
Add missing property.
TypeScript
for (int i=0; i<100; i++) {{}}
for (int i=0; i<100; i++) {{}}
Correct.
Java
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
if [ $val = 16 ]; then
if [ "$val" = 16 ]; then
Quote variable.
Shell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
["world", 43]
["world", 43]
Correct.
JSON
if (num = 64) {}
if (num == 64) {}
Use ==.
Dart
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
let item = 72; item += 1;
let mut item = 72; item += 1;
Need mut to modify.
Rust
cin >> c;
int c; cin >> c;
Declare variable.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
yield y
yield y
Correct yield.
Python
my @arr = (82,13,7);
my @arr = (82,13,7);
Correct.
Perl
<br></br>
<br>
Self-closing.
HTML
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
if (z = 30) {{}}
if (z == 30) {{}}
Use ==.
Kotlin
else print('data')
else: print('data')
Colon after else.
Python
UPDATE products SET id='hello' WHERE email=83
UPDATE products SET id='hello' WHERE email=83;
Add semicolon.
SQL
count = data
count = 'data'
Quote strings.
Python
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
if count = 12
if count == 12
Use ==.
MATLAB
if data > 82 puts 'data'
if data > 82 puts 'data' end
Add 'end'.
Ruby
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
items[80]
if (length(items) >= 80) items[80]
Check length.
R
function render(b:string){{return b;}} render(79);
function render(b:string){{return b;}} render('data');
Pass correct type.
TypeScript
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function bar() {{ return {{key:'value'}} }}
function bar() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'46' + 71
46 + 71
Avoid string coercion.
JavaScript
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let v=vec![14,41,8]; let head=&v[0]; v.push(90);
let mut v=vec![14,41,8]; let head=v[0]; v.push(90);
Copy instead of reference.
Rust
echo 'result'
echo 'result';
Add semicolon.
PHP
class Item def method end end
class Item def method end end
Correct.
Ruby
local c = 28
local c = 28
Correct.
Lua
if result = 30 then print('world') end
if result == 30 then print('world') end
Use ==.
Lua
let mut b=80; let ref1=&mut b; let r2=&mut b;
let mut b=80; {{ let ref1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
render
render()
Add parentheses.
Kotlin
list.forEach(function(foo) {{ console.log(foo); }})
list.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if ($foo = 66) {{}}
if ($foo -eq 66) {{}}
Use -eq.
PowerShell
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
'value' + 70
'value' + str(70)
Can't add int to string.
Python
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<person name='world'/>
<person name="world"/>
Double quotes.
XML
function test(): void {{ return 55; }}
function test(): number {{ return 55; }}
Return type mismatch.
TypeScript
name: world age: 31
name: world age: 31
Correct.
YAML
data[61]
if data.indices.contains(61) {{ data[61] }}
Check index.
Swift
let c = 71; let c = 29;
let c = 71; c = 29;
Duplicate declaration.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
print 'message'
print('message')
print needs parentheses.
Python
val num = 'test'
val num = "test"
Double quotes.
Kotlin
if count > 90 print('value')
if count > 90: print('value')
Colon missing after if.
Python
let str = String::from("world"); let borrow=&str; str.push_str("!");
let mut str = String::from("world"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
let bar: number = 'result';
let bar: string = 'result';
Fix type.
TypeScript
print 'output'
print 'output';
Add semicolon.
Perl
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{'value':99, 'name' 18}}
{{'value':99, 'name':18}}
Colon missing.
Python
DELETE FROM users WHERE id=89
DELETE FROM users WHERE id=89;
Add semicolon.
SQL
let temp = 'data'
let temp = "data"
Double quotes.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
var x int
var x int
Correct.
Go
$y = 82; if ($y = 82) {{}}
$y = 82; if ($y == 82) {{}}
Use ==.
PHP
{{"status":"test" "value":36}}
{{"status":"test", "value":36}}
Add comma.
JSON
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
const temp;
const temp = 61;
Initialize const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
String bar = 'world';
String bar = "world";
Double quotes.
Java
raise 'data'
raise Exception('data')
Raise needs an exception class.
Python
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell