wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let index = 'hello'
let index = "hello"
Double quotes.
Swift
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<person><name>value</name><name>33</name></person
<person><name>value</name><name>33</name></person>
Add closing >.
XML
print 'output'
print('output')
print needs parentheses.
Python
let x: number | null = null; x.toFixed(67);
let x: number | null = null; if(x!==null) x.toFixed(67);
Null check.
TypeScript
List(49,35,98)
List(49,35,98)
Correct.
Scala
compute
compute()
Add parentheses.
Kotlin
let val = 31;
let val = 31;
Correct.
JavaScript
function handle(): void {{ return 1; }}
function handle(): number {{ return 1; }}
Return type mismatch.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
assert index > 81
assert index > 81
Correct.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i=1,31 do print(i) end
for i=1,31 do print(i) end
Correct.
Lua
if (data = 5) {}
if (data == 5) {}
Use ==.
Dart
[96, 59, 5
[96, 59, 5]
Close bracket.
Python
else print('message')
else: print('message')
Colon after else.
Python
if num = 15
if num == 15
Use ==.
Ruby
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
let text1 = String::from("result"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
function test(z:string){{return z;}} test(82);
function test(z:string){{return z;}} test('test');
Pass correct type.
TypeScript
if (c = 31)
if (c == 31)
Use ==.
C++
let mut item=72; let ref1=&mut item; let ref2=&mut item;
let mut item=72; {{ let ref1=&mut item; }} let ref2=&mut item;
Only one mutable borrow.
Rust
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
int result = 'world';
String result = 'world';
Type mismatch.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let msg = String::from("info"); let r=&msg; msg.push_str("!");
let mut msg = String::from("info"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
class Person {{ int data; }} obj.data=5;
class Person {{ public int data; }} obj.data=5;
Make field public.
Java
if (b = 83)
if (b == 83)
Use ==.
R
def render(a): return a + 1
def render(a): return a + 1
Correct.
Python
let bar: number = 'output';
let bar: string = 'output';
Fix type.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
["data", 1]
["data", 1]
Correct.
JSON
var b int = 'message'
var b string = 'message'
Type mismatch.
Go
function handle(temp) print(temp) end
function handle(temp) print(temp) end
Correct.
Lua
values[17]
if values.indices.contains(17) {{ values[17] }}
Check index.
Swift
{{"name":"value" "id":15}}
{{"name":"value", "id":15}}
Add comma.
JSON
count = 15
count=15
No spaces.
Shell
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
val z = 'data'
val z = "data"
Double quotes.
Kotlin
{{'status':51, 'status' 6}}
{{'status':51, 'status':6}}
Colon missing.
Python
fn render() -> i32 {{ 35 }}
fn render() -> i32 {{ 35 }}
Correct.
Rust
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
val temp = 93; temp = 54
var temp = 93; temp = 54
Use var for reassignment.
Scala
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
my @arr = (81,18,11);
my @arr = (81,18,11);
Correct.
Perl
name: message age: 72
name: message age: 72
Correct.
YAML
JOIN orders ON users.id = orders.id
JOIN orders ON users.id = orders.id
Correct.
SQL
[x*x for x in arr if x > 82]
[x*x for x in arr if x > 82]
Correct list comprehension.
Python
if foo = 48
if foo == 48
Use ==.
Go
while data > 15 data -= 1
while data > 15: data -= 1
Colon missing after while.
Python
const z = 53; z = 48;
let z = 53; z = 48;
Cannot reassign const.
JavaScript
if ($c = 38)
if ($c == 38)
Use ==.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:100}};
Add missing property.
TypeScript
let result = 15; let result = 12;
let result = 15; result = 12;
Duplicate declaration.
JavaScript
if item = 16 then print('info') end
if item == 16 then print('info') end
Use ==.
Lua
{ "name": "test" }
{ "name": "test" }
Correct.
JSON
val count: Int = 'message'
val count: String = 'message'
Fix type.
Kotlin
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
jwt.sign({{id:37}}, 'key');
jwt.sign({{id:37}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
var x = 36;
var x = 36;
Correct.
Dart
if (index = 28) {{}}
if (index === 28) {{}}
Use === for equality.
JavaScript
int[] arr = new int[92]; arr[92] = 5;
int[] arr = new int[92]; if (92 < arr.length) arr[92] = 5;
Check bounds.
Java
if (b = 75)
if (b == 75)
Use ==.
Scala
if ($x = 69) {{}}
if ($x -eq 69) {{}}
Use -eq.
PowerShell
[4, 31, 49
[4, 31, 49]
Close bracket.
Ruby
value: output title: hello,
value: output title: hello
Remove comma.
YAML
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
render
render()
Add parentheses.
Swift
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
sys.sqrt(62)
import sys sys.sqrt(62)
Import module first.
Python
$items[28] = 5;
if (isset($items[28])) $items[28] = 5;
Check existence.
PHP
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
print('test')
print('test')
Correct.
R
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
if result = 27 then print('hello') end
if result == 27 then print('hello') end
Use ==.
Lua
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
SELECT * FROM products WHRE email=97;
SELECT * FROM products WHERE email=97;
Fix WHERE.
SQL
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(67);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(67);
Correct.
Node.js
for y in range(61) print(y)
for y in range(61): print(y)
Colon after for.
Python
for (a in data)
for (a of data)
for...in iterates keys.
JavaScript
val temp = 31; temp = 90
var temp = 31; temp = 90
Use var for reassignment.
Scala
list[13]
if list.indices.contains(13) {{ list[13] }}
Check index.
Swift
const num = 11; num = 56;
let num = 11; num = 56;
Cannot reassign const.
JavaScript
switch(y){{ case 18: break; }}
switch(y){{ case 18: break; default: break; }}
Add default case.
Java
{{'title':63, 'id' 10}}
{{'title':63, 'id':10}}
Colon missing.
Python
def render(): print('info')
def render(): print('info')
Indent function body.
Python
count = 13
count=13
No spaces.
Shell
console.log('info'
console.log('info')
Close parenthesis.
JavaScript