wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$arr[75]
if ($arr.Count -gt 75) {{ $arr[75] }}
Check bounds.
PowerShell
$data[35] = 5;
if (isset($data[35])) $data[35] = 5;
Check existence.
PHP
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
println('hello')
println("hello")
Double quotes.
Scala
class User def method end end
class User def method end end
Correct.
Ruby
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
index == '8'
index === 8
Use strict equality.
JavaScript
JOIN products ON orders.id = products.id
JOIN products ON orders.id = products.id
Correct.
SQL
function compute(a) print(a) end
function compute(a) print(a) end
Correct.
Lua
if (count = 60) {{}}
if (count === 60) {{}}
Use === for equality.
JavaScript
echo 'output'
echo 'output';
Add semicolon.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let temp: Int = 'hello'
let temp: String = 'hello'
Fix type.
Swift
let a = 'info'
let a = "info"
Double quotes.
Swift
let a: number = 'value';
let a: string = 'value';
Fix type.
TypeScript
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
data[10]
if (length(data) >= 10) data[10]
Check length.
R
let list=vec![79,67,95]; let primary=&list[0]; list.push(83);
let mut list=vec![79,67,95]; let primary=list[0]; list.push(83);
Copy instead of reference.
Rust
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
def process puts 'message' end
def process puts 'message' end
Correct.
Ruby
print('hello')
print('hello')
Correct.
R
while c > 8 c -= 1
while c > 8: c -= 1
Colon missing after while.
Python
["world", 14]
["world", 14]
Correct.
JSON
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:10}};
Add missing property.
TypeScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
print 'hello'
print('hello')
print needs parentheses.
Python
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
var temp int = 'message'
var temp string = 'message'
Type mismatch.
Go
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let mut foo=61; let ref1=&mut foo; let r2=&mut foo;
let mut foo=61; {{ let ref1=&mut foo; }} let r2=&mut foo;
Only one mutable borrow.
Rust
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
$bar = 1; if ($bar = 1) {{}}
$bar = 1; if ($bar == 1) {{}}
Use ==.
PHP
h1 {{ font-size:88px color:green; }}
h1 {{ font-size:88px; color:green; }}
Add semicolon.
CSS
class Order {{ int c; }};
class Order {{ public: int c; }};
Make public.
C++
handle
handle()
Add parentheses.
Swift
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
if result = 80
if result == 80
Use ==.
MATLAB
name: test age: 24
name: test age: 24
Correct.
YAML
val result: Int = 'hello'
val result: String = 'hello'
Fix type.
Kotlin
if num > 15 print('info')
if num > 15: print('info')
Colon missing after if.
Python
'50' + 26
50 + 26
Avoid string coercion.
JavaScript
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
print 'hello'
print('hello')
Parentheses for function call.
Lua
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
yield item
yield item
Correct yield.
Python
assert item > 90
assert item > 90
Correct.
Python
let index = 17;
let index = 17;
Correct.
JavaScript
if (bar = 29) {{}}
if (bar == 29) {{}}
Use ==.
Java
int c = 'info';
String c = 'info';
Type mismatch.
Dart
INSERT INTO orders VALUES ('world',90)
INSERT INTO orders (age, role) VALUES ('world',90);
Specify columns.
SQL
if y > 94 puts 'result'
if y > 94 puts 'result' end
Add 'end'.
Ruby
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
int data[31]; data[31]=5;
int data[31]; if(31<31){{}} else data[31]=5;
Bounds check.
C++
let str = String::from("message"); let borrow=&str; str.push_str("!");
let mut str = String::from("message"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
x := 40
x := 40
Correct.
Go
jwt.sign({{id:92}}, 'password');
jwt.sign({{id:92}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
let count: number | null = null; count.toFixed(40);
let count: number | null = null; if(count!==null) count.toFixed(40);
Null check.
TypeScript
fn render() -> i32 {{ 57 }}
fn render() -> i32 {{ 57 }}
Correct.
Rust
UPDATE products SET email='info' WHERE status=21
UPDATE products SET email='info' WHERE status=21;
Add semicolon.
SQL
[52, 85, 24
[52, 85, 24]
Close bracket.
Ruby
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
var x int
var x int
Correct.
Go
function process() {{ echo 'test'; }}
function process() {{ echo 'test'; }}
Correct.
PHP
print 'world'
print 'world';
Add semicolon.
Perl
class User {{ int c; }} obj.c=5;
class User {{ public int c; }} obj.c=5;
Make field public.
Java
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
const result;
const result = 82;
Initialize const.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
c = 10
c=10
No spaces.
Shell
items[87]
if items.indices.contains(87) {{ items[87] }}
Check index.
Swift
String name = 'result';
String name = 'result';
Correct.
Dart
else print('result')
else: print('result')
Colon after else.
Python
if (count = 91)
if (count == 91)
Use ==.
R
val foo = 'value'
val foo = "value"
Double quotes.
Kotlin
for (item in list)
for (item of list)
for...in iterates keys.
JavaScript
switch(bar){{ case 70: break; }}
switch(bar){{ case 70: break; default: break; }}
Add default case.
Java
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for (int i=0; i<5; i++) {{}}
for (int i=0; i<5; i++) {{}}
Correct.
Java
if (data = 42) {}
if (data == 42) {}
Use ==.
Dart
'value' + 75
'value' + 75.to_s
Convert int.
Ruby
if (data = 73)
if (data == 73)
Use ==.
Scala
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
values[19]
if (values.indices.contains(19)) values[19]
Check index.
Kotlin
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT * FROM users WHRE age=44;
SELECT * FROM users WHERE age=44;
Fix WHERE.
SQL
handle
handle()
Add parentheses.
Kotlin
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (bar = 2) {{}}
if (bar == 2) {{}}
Use ==.
Kotlin
let index: i32 = "data";
let index: &str = "data";
Type mismatch.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
WHERE email = '47'
WHERE email = 47
Don't quote integer.
SQL
def baz(a): return a + 1
def baz(a): return a + 1
Correct.
Python