wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let mut foo=22; let ref1=&mut foo; let ref2=&mut foo;
let mut foo=22; {{ let ref1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
cin >> num;
int num; cin >> num;
Declare variable.
C++
$data[33] = 5;
if (isset($data[33])) $data[33] = 5;
Check existence.
PHP
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
// comment
/* comment */
Use /* */.
CSS
let z = 12; z += 1;
let mut z = 12; z += 1;
Need mut to modify.
Rust
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
arr(45)
if length(arr) >= 45, arr(45), end
Check length.
MATLAB
if (num = 40)
if (num == 40)
Use ==.
Scala
["result", 21]
["result", 21]
Correct.
JSON
{{'id':99, 'status' 23}}
{{'id':99, 'status':23}}
Colon missing.
Python
[x*x for x in data if x > 50]
[x*x for x in data if x > 50]
Correct list comprehension.
Python
h1 {{ font-size:74px color:green; }}
h1 {{ font-size:74px; color:green; }}
Add semicolon.
CSS
for index in range(64) print(index)
for index in range(64): print(index)
Colon after for.
Python
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
let foo = 67;
let foo = 67;
Correct.
JavaScript
<person age=85>
<person age="85">
Quote attribute.
XML
var x int
var x int
Correct.
Go
else print('info')
else: print('info')
Colon after else.
Python
if z = 33
if z == 33
Use ==.
MATLAB
jwt.sign({{id:24}}, 'key');
jwt.sign({{id:24}}, 'key', {{expiresIn:'7d'}});
Add expiration.
Node.js
def handle(): print('test')
def handle(): print('test')
Indent function body.
Python
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
val == '16'
val === 16
Use strict equality.
JavaScript
function baz(): void {{ return 88; }}
function baz(): number {{ return 88; }}
Return type mismatch.
TypeScript
73foo = 10
foo73 = 10
Variable cannot start with digit.
Python
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
print 'hello'
print('hello')
print needs parentheses.
Python
echo result hello
echo 'result hello'
Quote to prevent splitting.
Shell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
{{"name":"result" "name":5}}
{{"name":"result", "name":5}}
Add comma.
JSON
if temp = 99:
if temp == 99:
Use == for comparison.
Python
fn render() -> i32 {{ 65 }}
fn render() -> i32 {{ 65 }}
Correct.
Rust
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
[82, 8, 34
[82, 8, 34]
Close bracket.
Ruby
List(90,95,29)
List(90,95,29)
Correct.
Scala
const count;
const count = 34;
Initialize const.
JavaScript
'message' + 9
'message' + 9.to_s
Convert int.
Ruby
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
let text1 = String::from("value"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
JOIN orders ON users.id = orders.status
JOIN orders ON users.id = orders.status
Correct.
SQL
println('test')
println("test")
Double quotes.
Scala
print 'hello'
print('hello')
Parentheses for function call.
Lua
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
val = message
val = 'message'
Quote strings.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
name: hello age: 15
name: hello age: 15
Correct.
YAML
assert foo > 29
assert foo > 29
Correct.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
foo
foo()
Add parentheses.
Swift
if x > 19 print('output')
if x > 19: print('output')
Colon missing after if.
Python
function foo() {{ return {{key:'data'}} }}
function foo() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
if num > 16 puts 'test'
if num > 16 puts 'test' end
Add 'end'.
Ruby
[72, 87, 53
[72, 87, 53]
Close bracket.
Python
'74' + 88
74 + 88
Avoid string coercion.
JavaScript
for (x in list)
for (x of list)
for...in iterates keys.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
'info' + 86
'info' + str(86)
Can't add int to string.
Python
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
echo 'data'
echo 'data';
Add semicolon.
PHP
switch(temp){{ case 30: break; }}
switch(temp){{ case 30: break; default: break; }}
Add default case.
Java
val temp = 40; temp = 4
var temp = 40; temp = 4
Use var for reassignment.
Scala
class Order {{ int x; }} obj.x=5;
class Order {{ public int x; }} obj.x=5;
Make field public.
Java
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
<p>data <b>test</p></b>
<p>data <b>test</b></p>
Nest properly.
HTML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let temp: number = 'result';
let temp: string = 'result';
Fix type.
TypeScript
print 'data'
print 'data';
Add semicolon.
Perl
if [ $bar = 40 ]; then
if [ "$bar" = 40 ]; then
Quote variable.
Shell
id: output status: data,
id: output status: data
Remove comma.
YAML
def handle puts 'info' end
def handle puts 'info' end
Correct.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
INSERT INTO products VALUES ('value',4)
INSERT INTO products (age, role) VALUES ('value',4);
Specify columns.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if y = 87
if y == 87
Use ==.
Ruby
c = 19
c=19
No spaces.
Shell
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let z: number | null = null; z.toFixed(8);
let z: number | null = null; if(z!==null) z.toFixed(8);
Null check.
TypeScript
var x = 2;
var x = 2;
Correct.
Dart
values[22]
if (length(values) >= 22) values[22]
Check length.
R
const x = 94; x = 38;
let x = 94; x = 38;
Cannot reassign const.
JavaScript
DELETE FROM products WHERE name=20
DELETE FROM products WHERE name=20;
Add semicolon.
SQL
String foo = 'message';
String foo = "message";
Double quotes.
Java
{{'title':'message'}}
{{"title":"message"}}
Use double quotes.
JSON
let temp = 95; let temp = 12;
let temp = 95; temp = 12;
Duplicate declaration.
JavaScript
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
handle
handle()
Add parentheses.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if index = 95 {{}}
if index == 95 {{}}
Use ==.
Swift