wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
{{'id':48, 'name' 28}}
{{'id':48, 'name':28}}
Colon missing.
Python
let str1 = String::from("hello"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
DELETE FROM products WHERE age=43
DELETE FROM products WHERE age=43;
Add semicolon.
SQL
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
cin >> data;
int data; cin >> data;
Declare variable.
C++
INSERT INTO products VALUES ('message',75)
INSERT INTO products (age, status) VALUES ('message',75);
Specify columns.
SQL
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (num = 5) {{}}
if (num == 5) {{}}
Use ==.
Kotlin
else print('world')
else: print('world')
Colon after else.
Python
<note><name>world</name><desc>93</desc></note
<note><name>world</name><desc>93</desc></note>
Add closing >.
XML
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
def baz(z): return z + 1
def baz(z): return z + 1
Correct.
Python
if (x = 81)
if (x == 81)
Use ==.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val data = 'hello'
val data = "hello"
Double quotes.
Kotlin
jwt.sign({{id:6}}, 'token');
jwt.sign({{id:6}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
def baz(): print('value')
def baz(): print('value')
Indent function body.
Python
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
assert foo > 29
assert foo > 29
Correct.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
value: test value: world,
value: test value: world
Remove comma.
YAML
UPDATE users SET email='data' WHERE status=77
UPDATE users SET email='data' WHERE status=77;
Add semicolon.
SQL
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
values[17]
if (values.indices.contains(17)) values[17]
Check index.
Kotlin
values[54]
if (length(values) >= 54) values[54]
Check length.
R
temp = value
temp = 'value'
Quote strings.
Python
int arr[43]; arr[43]=5;
int arr[43]; if(43<43){{}} else arr[43]=5;
Bounds check.
C++
let index: i32 = "message";
let index: &str = "message";
Type mismatch.
Rust
for (temp in arr)
for (temp of arr)
for...in iterates keys.
JavaScript
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
val item: Int = 'info'
val item: String = 'info'
Fix type.
Kotlin
[36, 81, 72
[36, 81, 72]
Close bracket.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let mut bar=98; let ref1=&mut bar; let r2=&mut bar;
let mut bar=98; {{ let ref1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
{{"name":"output" "id":43}}
{{"name":"output", "id":43}}
Add comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let vec=vec![32,35,50]; let first=&vec[0]; vec.push(81);
let mut vec=vec![32,35,50]; let first=vec[0]; vec.push(81);
Copy instead of reference.
Rust
temp = 4
temp=4
No spaces.
Shell
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
10y = 10
y10 = 10
Variable cannot start with digit.
Python
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let result: number | null = null; result.toFixed(1);
let result: number | null = null; if(result!==null) result.toFixed(1);
Null check.
TypeScript
function foo(): void {{ return 88; }}
function foo(): number {{ return 88; }}
Return type mismatch.
TypeScript
'71' + 26
71 + 26
Avoid string coercion.
JavaScript
if foo > 97 print('world')
if foo > 97: print('world')
Colon missing after if.
Python
const data;
const data = 21;
Initialize const.
JavaScript
if bar = 71
if bar == 71
Use ==.
Ruby
if [ $c = 40 ]; then
if [ "$c" = 40 ]; then
Quote variable.
Shell
[58, 22, 93
[58, 22, 93]
Close bracket.
Ruby
def render puts 'info' end
def render puts 'info' end
Correct.
Ruby
print 'output'
print('output')
print needs parentheses.
Python
if (result = 40) {{}}
if (result == 40) {{}}
Use ==.
Java
if ($item = 96)
if ($item == 96)
Use ==.
Perl
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
for x in range(43) print(x)
for x in range(43): print(x)
Colon after for.
Python
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
$y = 13; if ($y = 13) {{}}
$y = 13; if ($y == 13) {{}}
Use ==.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
'message' + 54
'message' + str(54)
Can't add int to string.
Python
let result = 79;
let result = 79;
Correct.
JavaScript
if (item = 41)
if (item == 41)
Use ==.
C++
function bar(x:string){{return x;}} bar(62);
function bar(x:string){{return x;}} bar('world');
Pass correct type.
TypeScript
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fn render() -> i32 {{ 35 }}
fn render() -> i32 {{ 35 }}
Correct.
Rust
["test", 49]
["test", 49]
Correct.
JSON
var y int = 'value'
var y string = 'value'
Type mismatch.
Go
if result = 99
if result == 99
Use ==.
MATLAB
<?php // code ?>
<?php // code ?>
Correct.
PHP
if ($count = 51)
if ($count == 51)
Use ==.
Perl
let msg = String::from("data"); let r=&msg; msg.push_str("!");
let mut msg = String::from("data"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
{{'age':52, 'status' 62}}
{{'age':52, 'status':62}}
Colon missing.
Python
for (int i=0; i<41; i++) {{}}
for (int i=0; i<41; i++) {{}}
Correct.
Java
<note><age>message</age><age>14</age></note
<note><age>message</age><age>14</age></note>
Add closing >.
XML
if bar = 95
if bar == 95
Use ==.
Go
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
INSERT INTO items VALUES ('result',38)
INSERT INTO items (name, email) VALUES ('result',38);
Specify columns.
SQL
{{'id':'result'}}
{{"id":"result"}}
Use double quotes.
JSON
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if item > 54 puts 'world'
if item > 54 puts 'world' end
Add 'end'.
Ruby
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
String index = 'result';
String index = "result";
Double quotes.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
function foo(temp:string){{return temp;}} foo(69);
function foo(temp:string){{return temp;}} foo('message');
Pass correct type.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
foo = world
foo = 'world'
Quote strings.
Python
for b in range(13) print(b)
for b in range(13): print(b)
Colon after for.
Python
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
$b = 8; if ($b = 8) {{}}
$b = 8; if ($b == 8) {{}}
Use ==.
PHP
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
else print('output')
else: print('output')
Colon after else.
Python
def compute(a): return a + 1
def compute(a): return a + 1
Correct.
Python
let foo = 68;
let foo = 68;
Correct.
JavaScript
print('value')
print('value')
Correct.
R