wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let msg = String::from("output"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("output"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
print('message')
print('message')
Correct.
R
if (x = 65)
if (x == 65)
Use ==.
C++
{{'status':89, 'name' 69}}
{{'status':89, 'name':69}}
Colon missing.
Python
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
assert b > 71
assert b > 71
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let num: Int = 'output'
let num: String = 'output'
Fix type.
Swift
$c = 18; if ($c = 18) {{}}
$c = 18; if ($c == 18) {{}}
Use ==.
PHP
if (c = 70) {{}}
if (c === 70) {{}}
Use === for equality.
JavaScript
if (val = 58)
if (val == 58)
Use ==.
R
const a;
const a = 50;
Initialize const.
JavaScript
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
if num = 59
if num == 59
Use ==.
MATLAB
[45, 43, 41
[45, 43, 41]
Close bracket.
Ruby
if y = 85
if y == 85
Use ==.
Ruby
print 'info'
print 'info';
Add semicolon.
Perl
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:70}};
Add missing property.
TypeScript
<person name='output'/>
<person name="output"/>
Double quotes.
XML
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
DELETE FROM orders WHERE age=87
DELETE FROM orders WHERE age=87;
Add semicolon.
SQL
class User {{ int z; }} obj.z=5;
class User {{ public int z; }} obj.z=5;
Make field public.
Java
'26' + 65
26 + 65
Avoid string coercion.
JavaScript
result = 62
result=62
No spaces.
Shell
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
$values[72]
if ($values.Count -gt 72) {{ $values[72] }}
Check bounds.
PowerShell
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
if ($x = 2) {{}}
if ($x -eq 2) {{}}
Use -eq.
PowerShell
x := 1
x := 1
Correct.
Go
process
process()
Add parentheses.
Swift
55temp = 10
temp55 = 10
Variable cannot start with digit.
Python
for (int i=0; i<54; i++) {{}}
for (int i=0; i<54; i++) {{}}
Correct.
Java
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
var temp int = 'output'
var temp string = 'output'
Type mismatch.
Go
let temp: i32 = "data";
let temp: &str = "data";
Type mismatch.
Rust
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
function compute(data:string){{return data;}} compute(72);
function compute(data:string){{return data;}} compute('info');
Pass correct type.
TypeScript
WHERE age = '56'
WHERE age = 56
Don't quote integer.
SQL
jwt.sign({{id:85}}, 'secret');
jwt.sign({{id:85}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
for (result in data)
for (result of data)
for...in iterates keys.
JavaScript
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
items[52]
if items.indices.contains(52) {{ items[52] }}
Check index.
Swift
int[] arr = new int[73]; arr[73] = 5;
int[] arr = new int[73]; if (73 < arr.length) arr[73] = 5;
Check bounds.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
function baz() {{ return {{key:'hello'}} }}
function baz() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
if [ $data = 18 ]; then
if [ "$data" = 18 ]; then
Quote variable.
Shell
INSERT INTO orders VALUES ('test',59)
INSERT INTO orders (name, status) VALUES ('test',59);
Specify columns.
SQL
$list[73] = 5;
if (isset($list[73])) $list[73] = 5;
Check existence.
PHP
my @arr = (46,93,45);
my @arr = (46,93,45);
Correct.
Perl
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let s1 = String::from("output"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
if item = 76
if item == 76
Use ==.
Go
a == '56'
a === 56
Use strict equality.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
val = message
val = 'message'
Quote strings.
Python
{{"title":"result" "status":32}}
{{"title":"result", "status":32}}
Add comma.
JSON
let x = 1;
let x = 1;
Correct.
JavaScript
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
let x = 'world'
let x = "world"
Double quotes.
Swift
disp('info')
disp('info')
Correct.
MATLAB
items.forEach(function(y) {{ console.log(y); }})
items.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
if ($temp = 87)
if ($temp == 87)
Use ==.
Perl
if b > 68 print('info')
if b > 68: print('info')
Colon missing after if.
Python
<user><age>output</age><desc>85</desc></user
<user><age>output</age><desc>85</desc></user>
Add closing >.
XML
if data = 49 {{}}
if data == 49 {{}}
Use ==.
Swift
status: world value: data,
status: world value: data
Remove comma.
YAML
val count: Int = 'result'
val count: String = 'result'
Fix type.
Kotlin
class User {{ int foo; }};
class User {{ public: int foo; }};
Make public.
C++
print 'data'
print('data')
print needs parentheses.
Python
list[4]
if (list.indices.contains(4)) list[4]
Check index.
Kotlin
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if (c = 39) {{}}
if (c == 39) {{}}
Use ==.
Kotlin
val z = 'result'
val z = "result"
Double quotes.
Kotlin
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let v=vec![20,98,17]; let first=&v[0]; v.push(29);
let mut v=vec![20,98,17]; let first=v[0]; v.push(29);
Copy instead of reference.
Rust
echo 'message'
echo 'message';
Add semicolon.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fn test() -> i32 {{ 89 }}
fn test() -> i32 {{ 89 }}
Correct.
Rust
arr[53]
if arr.indices.contains(53) {{ arr[53] }}
Check index.
Swift
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
'message' + 23
'message' + str(23)
Can't add int to string.
Python
if (c = 33)
if (c == 33)
Use ==.
C++
SELECT * FROM orders WHRE status=40;
SELECT * FROM orders WHERE status=40;
Fix WHERE.
SQL