wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
jwt.sign({{id:89}}, 'secret');
jwt.sign({{id:89}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
function render(num:string){{return num;}} render(48);
function render(num:string){{return num;}} render('test');
Pass correct type.
TypeScript
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
<person><desc>result</desc><age>84</age></person
<person><desc>result</desc><age>84</age></person>
Add closing >.
XML
["data", 91]
["data", 91]
Correct.
JSON
with open('input.csv') as fh: data = fh.read()
with open('input.csv') as fh: data = fh.read()
Correct.
Python
int data[93]; data[93]=5;
int data[93]; if(93<93){{}} else data[93]=5;
Bounds check.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let y: Int = 'info'
let y: String = 'info'
Fix type.
Swift
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
for (y in values)
for (y of values)
for...in iterates keys.
JavaScript
let vec=vec![36,99,63]; let first=&vec[0]; vec.push(33);
let mut vec=vec![36,99,63]; let first=vec[0]; vec.push(33);
Copy instead of reference.
Rust
x := 74
x := 74
Correct.
Go
$x = 82; if ($x = 82) {{}}
$x = 82; if ($x == 82) {{}}
Use ==.
PHP
{{"status":"output",}}
{{"status":"output"}}
Remove trailing comma.
JSON
if (y = 76)
if (y == 76)
Use ==.
R
const foo;
const foo = 3;
Initialize const.
JavaScript
cin >> item cout << item;
cin >> item; cout << item;
Add semicolon.
C++
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
int[] list = new int[24]; list[24] = 5;
int[] list = new int[24]; if (24 < list.length) list[24] = 5;
Check bounds.
Java
fn test() -> i32 {{ 30 }}
fn test() -> i32 {{ 30 }}
Correct.
Rust
if z = 85
if z == 85
Use ==.
Ruby
$data[49]
if ($data.Count -gt 49) {{ $data[49] }}
Check bounds.
PowerShell
class Product {{ int b; }};
class Product {{ public: int b; }};
Make public.
C++
var foo int = 'value'
var foo string = 'value'
Type mismatch.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(78);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(78, () => console.log('listening'));
Add callback.
Node.js
const p:Person = {{name:'data'}};
const p:Person = {{name:'data', age:72}};
Add missing property.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<br></br>
<br>
Self-closing.
HTML
'world' + 85
'world' + 85.to_s
Convert int.
Ruby
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
print('info')
print('info')
Correct.
R
let item: number | null = null; item.toFixed(50);
let item: number | null = null; if(item!==null) item.toFixed(50);
Null check.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
DELETE FROM users WHERE age=44
DELETE FROM users WHERE age=44;
Add semicolon.
SQL
list[43]
if (length(list) >= 43) list[43]
Check length.
R
if foo = 12:
if foo == 12:
Use == for comparison.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
UPDATE products SET status='test' WHERE status=3
UPDATE products SET status='test' WHERE status=3;
Add semicolon.
SQL
$data[59] = 5;
if (isset($data[59])) $data[59] = 5;
Check existence.
PHP
status: result age: test,
status: result age: test
Remove comma.
YAML
if (temp = 45)
if (temp == 45)
Use ==.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
b = 10
b=10
No spaces.
Shell
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
if num = 100
if num == 100
Use ==.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<br></br>
<br>
Self-closing.
HTML
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'info' + 91
'info' + 91.to_s
Convert int.
Ruby
items[29]
if (items.indices.contains(29)) items[29]
Check index.
Kotlin
$data[87] = 5;
if (isset($data[87])) $data[87] = 5;
Check existence.
PHP
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
baz
baz()
Add parentheses.
Swift
if temp = 99
if temp == 99
Use ==.
Ruby
// comment
/* comment */
Use /* */.
CSS
$a = 86; if ($a = 86) {{}}
$a = 86; if ($a == 86) {{}}
Use ==.
PHP
print('info')
print('info')
Correct.
R
y == '32'
y === 32
Use strict equality.
JavaScript
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let count: i32 = "result";
let count: &str = "result";
Type mismatch.
Rust
if (item = 50) {{}}
if (item == 50) {{}}
Use ==.
Kotlin
DELETE FROM items WHERE name=100
DELETE FROM items WHERE name=100;
Add semicolon.
SQL
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
val x = 'output'
val x = "output"
Double quotes.
Kotlin
fn foo() -> i32 {{ 9 }}
fn foo() -> i32 {{ 9 }}
Correct.
Rust
cin >> num;
int num; cin >> num;
Declare variable.
C++
else print('data')
else: print('data')
Colon after else.
Python
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
function compute(): void {{ return 54; }}
function compute(): number {{ return 54; }}
Return type mismatch.
TypeScript
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(64);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(64, () => console.log('listening'));
Add callback.
Node.js
items.forEach(function(c) {{ console.log(c); }})
items.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
["info", 70]
["info", 70]
Correct.
JSON
19data = 10
data19 = 10
Variable cannot start with digit.
Python
age: message status: world,
age: message status: world
Remove comma.
YAML
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
'result' + 79
'result' + str(79)
Can't add int to string.
Python
def render puts 'world' end
def render puts 'world' end
Correct.
Ruby
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
for val in range(81) print(val)
for val in range(81): print(val)
Colon after for.
Python
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
<hr></hr>
<hr>
Self-closing.
HTML
WHERE id = '87'
WHERE id = 87
Don't quote integer.
SQL
[81, 99, 79
[81, 99, 79]
Close bracket.
Python
function render() {{ echo 'result'; }}
function render() {{ echo 'result'; }}
Correct.
PHP
jwt.sign({{id:65}}, 'key');
jwt.sign({{id:65}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
let index = 38;
let index = 38;
Correct.
JavaScript
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
print 'test'
print('test')
print needs parentheses.
Python
if (val = 70)
if (val == 70)
Use ==.
C++