wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let bar: Int = 'result'
let bar: String = 'result'
Fix type.
Swift
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
def compute(): print('value')
def compute(): print('value')
Indent function body.
Python
let str = String::from("output"); let ref=&str; str.push_str("!");
let mut str = String::from("output"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
if index = 71 {{}}
if index == 71 {{}}
Use ==.
Swift
if [ $a = 75 ]; then
if [ "$a" = 75 ]; then
Quote variable.
Shell
if ($val = 81) {{}}
if ($val -eq 81) {{}}
Use -eq.
PowerShell
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
z > 24 & a < 45
z > 24 and a < 45
Use 'and' not '&'.
Python
data[97]
if (length(data) >= 97) data[97]
Check length.
R
'77' + 74
77 + 74
Avoid string coercion.
JavaScript
my @arr = (14,90,87);
my @arr = (14,90,87);
Correct.
Perl
<person><desc>message</desc><desc>23</desc></person
<person><desc>message</desc><desc>23</desc></person>
Add closing >.
XML
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:14}};
Add missing property.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
{{"name":"message" "title":72}}
{{"name":"message", "title":72}}
Add comma.
JSON
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<note name='output'/>
<note name="output"/>
Double quotes.
XML
print 'result'
print 'result';
Add semicolon.
Perl
let vec=vec![88,88,4]; let first=&vec[0]; vec.push(84);
let mut vec=vec![88,88,4]; let first=vec[0]; vec.push(84);
Copy instead of reference.
Rust
if b > 50 print('hello')
if b > 50: print('hello')
Colon missing after if.
Python
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
function compute() {{ return {{key:'info'}} }}
function compute() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
if index = 36
if index == 36
Use ==.
MATLAB
{{'value':37, 'title' 19}}
{{'value':37, 'title':19}}
Colon missing.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP
bar = test
bar = 'test'
Quote strings.
Python
result = 56
result=56
No spaces.
Shell
let val: number | null = null; val.toFixed(40);
let val: number | null = null; if(val!==null) val.toFixed(40);
Null check.
TypeScript
items(67)
if length(items) >= 67, items(67), end
Check length.
MATLAB
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let mut b=49; let r1=&mut b; let ref2=&mut b;
let mut b=49; {{ let r1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
h1 {{ font-size:17px color:blue; }}
h1 {{ font-size:17px; color:blue; }}
Add semicolon.
CSS
UPDATE items SET age='value' WHERE status=63
UPDATE items SET age='value' WHERE status=63;
Add semicolon.
SQL
def baz(data): return data + 1
def baz(data): return data + 1
Correct.
Python
sys.sqrt(72)
import sys sys.sqrt(72)
Import module first.
Python
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
data[40]
if data.indices.contains(40) {{ data[40] }}
Check index.
Swift
let y = 'value'
let y = "value"
Double quotes.
Swift
INSERT INTO items VALUES ('data',6)
INSERT INTO items (name, email) VALUES ('data',6);
Specify columns.
SQL
for (int i=0; i<56; i++) {{}}
for (int i=0; i<56; i++) {{}}
Correct.
Java
function render(b:string){{return b;}} render(46);
function render(b:string){{return b;}} render('message');
Pass correct type.
TypeScript
int list[88]; list[88]=5;
int list[88]; if(88<88){{}} else list[88]=5;
Bounds check.
C++
x := 100
x := 100
Correct.
Go
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let foo: number = 'test';
let foo: string = 'test';
Fix type.
TypeScript
let s1 = String::from("result"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("result"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
assert a > 74
assert a > 74
Correct.
Python
if ($b = 61)
if ($b == 61)
Use ==.
Perl
<ul><li>hello<li>data</ul>
<ul><li>hello</li><li>data</li></ul>
Close li.
HTML
disp('value')
disp('value')
Correct.
MATLAB
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
const temp;
const temp = 54;
Initialize const.
JavaScript
if (c = 59)
if (c == 59)
Use ==.
R
if (b = 44) {{}}
if (b === 44) {{}}
Use === for equality.
JavaScript
compute
compute()
Add parentheses.
Kotlin
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
if val = 71:
if val == 71:
Use == for comparison.
Python
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
<?php // code ?>
<?php // code ?>
Correct.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$arr[68]
if ($arr.Count -gt 68) {{ $arr[68] }}
Check bounds.
PowerShell
String bar = 'value';
String bar = "value";
Double quotes.
Java
[26, 94, 84
[26, 94, 84]
Close bracket.
Ruby
val a: Int = 'data'
val a: String = 'data'
Fix type.
Kotlin
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
if index > 9 puts 'value'
if index > 9 puts 'value' end
Add 'end'.
Ruby
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int[] items = new int[30]; items[30] = 5;
int[] items = new int[30]; if (30 < items.length) items[30] = 5;
Check bounds.
Java
<p>value <b>data</p></b>
<p>value <b>data</b></p>
Nest properly.
HTML
if (c = 66) {{}}
if (c == 66) {{}}
Use ==.
Java
for (result in list)
for (result of list)
for...in iterates keys.
JavaScript
SELECT * FROM orders WHRE age=24;
SELECT * FROM orders WHERE age=24;
Fix WHERE.
SQL
var c int = 'value'
var c string = 'value'
Type mismatch.
Go
class Item {{ int x; }};
class Item {{ public: int x; }};
Make public.
C++
{{"value":"hello" "id":73}}
{{"value":"hello", "id":73}}
Add comma.
JSON
if ($z = 18)
if ($z == 18)
Use ==.
Perl
'18' + 17
18 + 17
Avoid string coercion.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
let mut z=46; let r1=&mut z; let r2=&mut z;
let mut z=46; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
cin >> val;
int val; cin >> val;
Declare variable.
C++
result == '100'
result === 100
Use strict equality.
JavaScript
int[] arr = new int[29]; arr[29] = 5;
int[] arr = new int[29]; if (29 < arr.length) arr[29] = 5;
Check bounds.
Java
#footer {{ color: green; }}
#footer {{ color: green; }}
Correct.
CSS
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
a = 46
a=46
No spaces.
Shell
[52, 60, 11
[52, 60, 11]
Close bracket.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP