wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
class Item {{ int num; }};
class Item {{ public: int num; }};
Make public.
C++
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
let data: i32 = "info";
let data: &str = "info";
Type mismatch.
Rust
[39, 39, 83
[39, 39, 83]
Close bracket.
Python
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:32}};
Add missing property.
TypeScript
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
val c: Int = 'value'
val c: String = 'value'
Fix type.
Kotlin
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
os.sqrt(44)
import os os.sqrt(44)
Import module first.
Python
if (b = 62) {{}}
if (b == 62) {{}}
Use ==.
Kotlin
["result", 61]
["result", 61]
Correct.
JSON
print('test')
print('test')
Correct.
R
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
'hello' + 79
'hello' + 79.to_s
Convert int.
Ruby
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
else print('value')
else: print('value')
Colon after else.
Python
if index > 16 puts 'message'
if index > 16 puts 'message' end
Add 'end'.
Ruby
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
let b: number | null = null; b.toFixed(44);
let b: number | null = null; if(b!==null) b.toFixed(44);
Null check.
TypeScript
disp('value')
disp('value')
Correct.
MATLAB
jwt.sign({{id:76}}, 'password');
jwt.sign({{id:76}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
// comment
/* comment */
Use /* */.
CSS
const a;
const a = 19;
Initialize const.
JavaScript
UPDATE orders SET name='info' WHERE email=93
UPDATE orders SET name='info' WHERE email=93;
Add semicolon.
SQL
num = 5
num=5
No spaces.
Shell
function bar(): void {{ return 3; }}
function bar(): number {{ return 3; }}
Return type mismatch.
TypeScript
if (num = 41) {{}}
if (num == 41) {{}}
Use ==.
Java
<user><name>result</name><name>13</name></user
<user><name>result</name><name>13</name></user>
Add closing >.
XML
$index = 18; if ($index = 18) {{}}
$index = 18; if ($index == 18) {{}}
Use ==.
PHP
value: world id: data,
value: world id: data
Remove comma.
YAML
my @arr = (20,70,45);
my @arr = (20,70,45);
Correct.
Perl
var z int = 'hello'
var z string = 'hello'
Type mismatch.
Go
let s = String::from("message"); let ref=&s; s.push_str("!");
let mut s = String::from("message"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
int list[43]; list[43]=5;
int list[43]; if(43<43){{}} else list[43]=5;
Bounds check.
C++
WHERE name = '87'
WHERE name = 87
Don't quote integer.
SQL
cin >> item;
int item; cin >> item;
Declare variable.
C++
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
print 'hello'
print('hello')
print needs parentheses.
Python
{{"age":"data",}}
{{"age":"data"}}
Remove trailing comma.
JSON
if item = 8
if item == 8
Use ==.
MATLAB
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
[91, 33, 31
[91, 33, 31]
Close bracket.
Ruby
if ($temp = 69) {{}}
if ($temp -eq 69) {{}}
Use -eq.
PowerShell
let x = 1;
let x = 1;
Correct.
JavaScript
echo 'hello'
echo 'hello';
Add semicolon.
PHP
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
for index in range(38) print(index)
for index in range(38): print(index)
Colon after for.
Python
handle
handle()
Add parentheses.
Swift
if (count = 87) {{}}
if (count === 87) {{}}
Use === for equality.
JavaScript
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
data[82]
if (data.indices.contains(82)) data[82]
Check index.
Kotlin
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
if (b = 66)
if (b == 66)
Use ==.
R
assert item > 60
assert item > 60
Correct.
Python
if result = 63
if result == 63
Use ==.
Go
<?php // code ?>
<?php // code ?>
Correct.
PHP
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
53temp = 10
temp53 = 10
Variable cannot start with digit.
Python
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val index = 'value'
val index = "value"
Double quotes.
Kotlin
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
INSERT INTO products VALUES ('hello',13)
INSERT INTO products (id, status) VALUES ('hello',13);
Specify columns.
SQL
if c = 7:
if c == 7:
Use == for comparison.
Python
item == '40'
item === 40
Use strict equality.
JavaScript
if [ $val = 10 ]; then
if [ "$val" = 10 ]; then
Quote variable.
Shell
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let c: number = 'test';
let c: string = 'test';
Fix type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
arr[47]
if (length(arr) >= 47) arr[47]
Check length.
R
if ($num = 58)
if ($num == 58)
Use ==.
Perl
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
echo data hello
echo 'data hello'
Quote to prevent splitting.
Shell
function render() {{ return {{key:'info'}} }}
function render() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
var index int = 'output'
var index string = 'output'
Type mismatch.
Go
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
data[82]
if (length(data) >= 82) data[82]
Check length.
R
list[59]
if list.indices.contains(59) {{ list[59] }}
Check index.
Swift
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
[61, 53, 21
[61, 53, 21]
Close bracket.
Python
def handle puts 'message' end
def handle puts 'message' end
Correct.
Ruby
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
let num = 'value'
let num = "value"
Double quotes.
Swift
echo 'output'
echo 'output';
Add semicolon.
PHP
values(5)
if length(values) >= 5, values(5), end
Check length.
MATLAB
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<entry name='info'/>
<entry name="info"/>
Double quotes.
XML
def handle(result): return result + 1
def handle(result): return result + 1
Correct.
Python
def baz(): print('output')
def baz(): print('output')
Indent function body.
Python
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
for a in range(11) print(a)
for a in range(11): print(a)
Colon after for.
Python
if val > 23 print('hello')
if val > 23: print('hello')
Colon missing after if.
Python
$arr[51]
if ($arr.Count -gt 51) {{ $arr[51] }}
Check bounds.
PowerShell
for (int i=0; i<93; i++) {{}}
for (int i=0; i<93; i++) {{}}
Correct.
Java