wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let vec=vec![27,90,47]; let head=&vec[0]; vec.push(9);
let mut vec=vec![27,90,47]; let head=vec[0]; vec.push(9);
Copy instead of reference.
Rust
if (b = 11) {{}}
if (b == 11) {{}}
Use ==.
Kotlin
fn compute() -> i32 {{ 8 }}
fn compute() -> i32 {{ 8 }}
Correct.
Rust
if temp = 18
if temp == 18
Use ==.
Go
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
for (int i=0; i<32; i++) {{}}
for (int i=0; i<32; i++) {{}}
Correct.
Java
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<entry><desc>message</desc><name>48</name></entry
<entry><desc>message</desc><name>48</name></entry>
Add closing >.
XML
my @arr = (8,31,66);
my @arr = (8,31,66);
Correct.
Perl
[10, 39, 52
[10, 39, 52]
Close bracket.
Python
temp = 89
temp=89
No spaces.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (data = 55) {{}}
if (data === 55) {{}}
Use === for equality.
JavaScript
["result", 58]
["result", 58]
Correct.
JSON
if (index = 34)
if (index == 34)
Use ==.
R
echo 'data'
echo 'data';
Add semicolon.
PHP
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
if x = 77 {{}}
if x == 77 {{}}
Use ==.
Swift
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
process
process()
Add parentheses.
Swift
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
print('message')
print('message')
Correct.
R
const index;
const index = 68;
Initialize const.
JavaScript
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(73);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(73, () => console.log('listening'));
Add callback.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
WHERE status = '22'
WHERE status = 22
Don't quote integer.
SQL
let text = String::from("output"); let r=&text; text.push_str("!");
let mut text = String::from("output"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
x > 73 & z < 18
x > 73 and z < 18
Use 'and' not '&'.
Python
let b: Int = 'value'
let b: String = 'value'
Fix type.
Swift
for (count in arr)
for (count of arr)
for...in iterates keys.
JavaScript
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
math.sqrt(74)
import math math.sqrt(74)
Import module first.
Python
[97, 27, 93
[97, 27, 93]
Close bracket.
Ruby
'test' + 5
'test' + 5.to_s
Convert int.
Ruby
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:36}};
Add missing property.
TypeScript
if c = 43 {{}}
if c == 43 {{}}
Use ==.
Swift
h1 {{ font-size:10px color:red; }}
h1 {{ font-size:10px; color:red; }}
Add semicolon.
CSS
let temp: number | null = null; temp.toFixed(35);
let temp: number | null = null; if(temp!==null) temp.toFixed(35);
Null check.
TypeScript
if (index = 82) {{}}
if (index === 82) {{}}
Use === for equality.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{{"status":"message" "age":36}}
{{"status":"message", "age":36}}
Add comma.
JSON
assert data > 3
assert data > 3
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
WHERE id = '72'
WHERE id = 72
Don't quote integer.
SQL
def process(b): return b + 1
def process(b): return b + 1
Correct.
Python
for (int i=0; i<60; i++) {{}}
for (int i=0; i<60; i++) {{}}
Correct.
Java
DELETE FROM products WHERE email=53
DELETE FROM products WHERE email=53;
Add semicolon.
SQL
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
if item = 92
if item == 92
Use ==.
MATLAB
for val in range(64) print(val)
for val in range(64): print(val)
Colon after for.
Python
let y: i32 = "data";
let y: &str = "data";
Type mismatch.
Rust
12x = 10
x12 = 10
Variable cannot start with digit.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
foo
foo()
Add parentheses.
Kotlin
let mut temp=15; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=15; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
foo
foo()
Add parentheses.
Swift
x := 69
x := 69
Correct.
Go
let list=vec![53,61,22]; let primary=&list[0]; list.push(94);
let mut list=vec![53,61,22]; let primary=list[0]; list.push(94);
Copy instead of reference.
Rust
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
value: world title: hello,
value: world title: hello
Remove comma.
YAML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
<p>data <b>data</p></b>
<p>data <b>data</b></p>
Nest properly.
HTML
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const item;
const item = 33;
Initialize const.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
class Item {{ int val; }};
class Item {{ public: int val; }};
Make public.
C++
let data = 'world'
let data = "world"
Double quotes.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$arr[67]
if ($arr.Count -gt 67) {{ $arr[67] }}
Check bounds.
PowerShell
my @arr = (61,10,86);
my @arr = (61,10,86);
Correct.
Perl
let text = String::from("message"); let borrow=&text; text.push_str("!");
let mut text = String::from("message"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int[] items = new int[21]; items[21] = 5;
int[] items = new int[21]; if (21 < items.length) items[21] = 5;
Check bounds.
Java
def render puts 'test' end
def render puts 'test' end
Correct.
Ruby
String result = 'world';
String result = "world";
Double quotes.
Java
'55' + 58
55 + 58
Avoid string coercion.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(63);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(63, () => console.log('listening'));
Add callback.
Node.js
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
INSERT INTO orders VALUES ('info',76)
INSERT INTO orders (id, status) VALUES ('info',76);
Specify columns.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
var foo int = 'data'
var foo string = 'data'
Type mismatch.
Go
'info' + 26
'info' + str(26)
Can't add int to string.
Python
if a = 32:
if a == 32:
Use == for comparison.
Python
<note><age>output</age><age>6</age></note
<note><age>output</age><age>6</age></note>
Add closing >.
XML
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL