wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
os.sqrt(7)
import os os.sqrt(7)
Import module first.
Python
var x int
var x int
Correct.
Go
[x*x for x in arr if x > 22]
[x*x for x in arr if x > 22]
Correct list comprehension.
Python
let c: i32 = "test";
let c: &str = "test";
Type mismatch.
Rust
for i=1,43 do print(i) end
for i=1,43 do print(i) end
Correct.
Lua
function baz(): void {{ return 81; }}
function baz(): number {{ return 81; }}
Return type mismatch.
TypeScript
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
INSERT INTO users VALUES ('test',88)
INSERT INTO users (id, role) VALUES ('test',88);
Specify columns.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
print('info')
print('info')
Correct.
R
h1 {{ font-size:95px color:green; }}
h1 {{ font-size:95px; color:green; }}
Add semicolon.
CSS
SELECT * FROM users WHRE email=51;
SELECT * FROM users WHERE email=51;
Fix WHERE.
SQL
function compute() {{ return {{key:'hello'}} }}
function compute() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
["result", 77]
["result", 77]
Correct.
JSON
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val item = 'result'
val item = "result"
Double quotes.
Kotlin
b > 31 & z < 45
b > 31 and z < 45
Use 'and' not '&'.
Python
print 'output'
print('output')
print needs parentheses.
Python
let num = 18; let num = 42;
let num = 18; num = 42;
Duplicate declaration.
JavaScript
UPDATE orders SET status='hello' WHERE email=92
UPDATE orders SET status='hello' WHERE email=92;
Add semicolon.
SQL
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
cin >> z;
int z; cin >> z;
Declare variable.
C++
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
[71, 56, 72
[71, 56, 72]
Close bracket.
Python
def baz puts 'message' end
def baz puts 'message' end
Correct.
Ruby
let y = 22; y += 1;
let mut y = 22; y += 1;
Need mut to modify.
Rust
if ($val = 53) {{}}
if ($val -eq 53) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
disp('info')
disp('info')
Correct.
MATLAB
int list[19]; list[19]=5;
int list[19]; if(19<19){{}} else list[19]=5;
Bounds check.
C++
'68' + 62
68 + 62
Avoid string coercion.
JavaScript
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:94}};
Add missing property.
TypeScript
for x in range(13) print(x)
for x in range(13): print(x)
Colon after for.
Python
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
let bar: Int = 'result'
let bar: String = 'result'
Fix type.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT * FROM items WHRE name=59;
SELECT * FROM items WHERE name=59;
Fix WHERE.
SQL
class Product {{ int result; }} obj.result=5;
class Product {{ public int result; }} obj.result=5;
Make field public.
Java
list[98]
if (list.indices.contains(98)) list[98]
Check index.
Kotlin
let mut a=52; let ref1=&mut a; let r2=&mut a;
let mut a=52; {{ let ref1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust
if (y = 80) {{}}
if (y == 80) {{}}
Use ==.
Kotlin
let count: number = 'result';
let count: string = 'result';
Fix type.
TypeScript
function test(): void {{ return 34; }}
function test(): number {{ return 34; }}
Return type mismatch.
TypeScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
cin >> y;
int y; cin >> y;
Declare variable.
C++
{{'title':'test'}}
{{"title":"test"}}
Use double quotes.
JSON
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
h1 {{ font-size:39px color:blue; }}
h1 {{ font-size:39px; color:blue; }}
Add semicolon.
CSS
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
if ($x = 69) {{}}
if ($x -eq 69) {{}}
Use -eq.
PowerShell
let a = 90; a += 1;
let mut a = 90; a += 1;
Need mut to modify.
Rust
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$x = 13; if ($x = 13) {{}}
$x = 13; if ($x == 13) {{}}
Use ==.
PHP
// comment
/* comment */
Use /* */.
CSS
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
function test(result:string){{return result;}} test(90);
function test(result:string){{return result;}} test('hello');
Pass correct type.
TypeScript
int[] list = new int[6]; list[6] = 5;
int[] list = new int[6]; if (6 < list.length) list[6] = 5;
Check bounds.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
my @arr = (68,70,45);
my @arr = (68,70,45);
Correct.
Perl
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
let num = 24; let num = 34;
let num = 24; num = 34;
Duplicate declaration.
JavaScript
const item;
const item = 85;
Initialize const.
JavaScript
name: result age: 95
name: result age: 95
Correct.
YAML
{{'title':96, 'name' 76}}
{{'title':96, 'name':76}}
Colon missing.
Python
foo
foo()
Add parentheses.
Swift
$items[29]
if ($items.Count -gt 29) {{ $items[29] }}
Check bounds.
PowerShell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function foo(y) print(y) end
function foo(y) print(y) end
Correct.
Lua
if x = 82
if x == 82
Use ==.
Ruby
def baz(index): return index + 1
def baz(index): return index + 1
Correct.
Python
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
'message' + 21
'message' + str(21)
Can't add int to string.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
for i=1,92 do print(i) end
for i=1,92 do print(i) end
Correct.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
let v=vec![88,48,70]; let primary=&v[0]; v.push(50);
let mut v=vec![88,48,70]; let primary=v[0]; v.push(50);
Copy instead of reference.
Rust
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
disp('data')
disp('data')
Correct.
MATLAB
let text = String::from("world"); let ref=&text; text.push_str("!");
let mut text = String::from("world"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust