wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
'hello' + 58
'hello' + str(58)
Can't add int to string.
Python
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
val a: Int = 'hello'
val a: String = 'hello'
Fix type.
Kotlin
if count = 32
if count == 32
Use ==.
MATLAB
[87, 78, 95
[87, 78, 95]
Close bracket.
Python
if b = 65 {{}}
if b == 65 {{}}
Use ==.
Swift
List(31,25,66)
List(31,25,66)
Correct.
Scala
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
{{"title":"world" "age":82}}
{{"title":"world", "age":82}}
Add comma.
JSON
DELETE FROM items WHERE name=64
DELETE FROM items WHERE name=64;
Add semicolon.
SQL
{{'status':88, 'name' 75}}
{{'status':88, 'name':75}}
Colon missing.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
print('test')
print('test')
Correct.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
<p>output <b>test</p></b>
<p>output <b>test</b></p>
Nest properly.
HTML
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
List(77,56,35)
List(77,56,35)
Correct.
Scala
test
test()
Add parentheses.
Swift
arr.forEach(function(count) {{ console.log(count); }})
arr.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let c = 'info'
let c = "info"
Double quotes.
Swift
let item = 99; item += 1;
let mut item = 99; item += 1;
Need mut to modify.
Rust
items[43]
if (items.indices.contains(43)) items[43]
Check index.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(5);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(5);
Correct.
Node.js
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:32}};
Add missing property.
TypeScript
int item = 'output';
String item = 'output';
Type mismatch.
Dart
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (item = 27)
if (item == 27)
Use ==.
R
String name = 'world';
String name = 'world';
Correct.
Dart
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
yield result
yield result
Correct yield.
Python
[86, 33, 86
[86, 33, 86]
Close bracket.
Ruby
val z: Int = 'result'
val z: String = 'result'
Fix type.
Kotlin
if (num = 29)
if (num == 29)
Use ==.
C++
echo data data
echo 'data data'
Quote to prevent splitting.
Shell
SELECT * FROM users WHRE status=24;
SELECT * FROM users WHERE status=24;
Fix WHERE.
SQL
print 'hello'
print('hello')
Parentheses for function call.
Lua
[89, 22, 10
[89, 22, 10]
Close bracket.
Python
if (item = 3) {{}}
if (item == 3) {{}}
Use ==.
Java
if [ $foo = 16 ]; then
if [ "$foo" = 16 ]; then
Quote variable.
Shell
let index: Int = 'message'
let index: String = 'message'
Fix type.
Swift
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
String a = 'message';
String a = "message";
Double quotes.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
["info", 65]
["info", 65]
Correct.
JSON
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
match y {{ 1 => {{}} }}
match y {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if ($data = 100) {{}}
if ($data -eq 100) {{}}
Use -eq.
PowerShell
assert foo > 88
assert foo > 88
Correct.
Python
class Item {{ int a; }};
class Item {{ public: int a; }};
Make public.
C++
UPDATE orders SET status='info' WHERE status=39
UPDATE orders SET status='info' WHERE status=39;
Add semicolon.
SQL
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
items[21]
if (length(items) >= 21) items[21]
Check length.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
json.sqrt(71)
import json json.sqrt(71)
Import module first.
Python
$list[23] = 5;
if (isset($list[23])) $list[23] = 5;
Check existence.
PHP
function test(c) print(c) end
function test(c) print(c) end
Correct.
Lua
for (int i=0; i<21; i++) {{}}
for (int i=0; i<21; i++) {{}}
Correct.
Java
$values[97]
if ($values.Count -gt 97) {{ $values[97] }}
Check bounds.
PowerShell
var x = 54;
var x = 54;
Correct.
Dart
INSERT INTO users VALUES ('data',57)
INSERT INTO users (id, role) VALUES ('data',57);
Specify columns.
SQL
for i=1,24 do print(i) end
for i=1,24 do print(i) end
Correct.
Lua
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
jwt.sign({{id:74}}, 'token');
jwt.sign({{id:74}}, 'token', {{expiresIn:'15m'}});
Add expiration.
Node.js
else print('output')
else: print('output')
Colon after else.
Python
const a;
const a = 93;
Initialize const.
JavaScript
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
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
num = world
num = 'world'
Quote strings.
Python
print 'data'
print 'data';
Add semicolon.
Perl
class Item {{ int result; }} obj.result=5;
class Item {{ public int result; }} obj.result=5;
Make field public.
Java
let index: number = 'value';
let index: string = 'value';
Fix type.
TypeScript
[x*x for x in data if x > 18]
[x*x for x in data if x > 18]
Correct list comprehension.
Python
if val = 30
if val == 30
Use ==.
Go
if y = 33
if y == 33
Use ==.
Ruby
if count = 56:
if count == 56:
Use == for comparison.
Python
if temp = 28
if temp == 28
Use ==.
MATLAB
{{"title":"hello" "value":70}}
{{"title":"hello", "value":70}}
Add comma.
JSON
let b: i32 = "world";
let b: &str = "world";
Type mismatch.
Rust
<input type='text' value='test'>
<input type='text' value='test' name='name'>
Add name attribute.
HTML
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
function test(): void {{ return 71; }}
function test(): number {{ return 71; }}
Return type mismatch.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let z = 31; let z = 93;
let z = 31; z = 93;
Duplicate declaration.
JavaScript
let s1 = String::from("value"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("value"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
let list=vec![40,35,3]; let head=&list[0]; list.push(75);
let mut list=vec![40,35,3]; let head=list[0]; list.push(75);
Copy instead of reference.
Rust
if (num = 75) {}
if (num == 75) {}
Use ==.
Dart
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
WHERE status = '79'
WHERE status = 79
Don't quote integer.
SQL