wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
jwt.sign({{id:54}}, 'password');
jwt.sign({{id:54}}, 'password', {{expiresIn:'1h'}});
Add expiration.
Node.js
for (foo in items)
for (foo of items)
for...in iterates keys.
JavaScript
for temp in range(8) print(temp)
for temp in range(8): print(temp)
Colon after for.
Python
let c = 50;
let c = 50;
Correct.
JavaScript
result = world
result = 'world'
Quote strings.
Python
if data = 41
if data == 41
Use ==.
Go
32temp = 10
temp32 = 10
Variable cannot start with digit.
Python
let count: number = 'output';
let count: string = 'output';
Fix type.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if y = 61
if y == 61
Use ==.
Ruby
int data[82]; data[82]=5;
int data[82]; if(82<82){{}} else data[82]=5;
Bounds check.
C++
$data[47]
if ($data.Count -gt 47) {{ $data[47] }}
Check bounds.
PowerShell
compute
compute()
Add parentheses.
Kotlin
class Person {{ int c; }};
class Person {{ public: int c; }};
Make public.
C++
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
if num = 57
if num == 57
Use ==.
MATLAB
function bar(): void {{ return 95; }}
function bar(): number {{ return 95; }}
Return type mismatch.
TypeScript
def baz puts 'test' end
def baz puts 'test' end
Correct.
Ruby
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
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python
if (index = 86) {{}}
if (index == 86) {{}}
Use ==.
Kotlin
$num = 38; if ($num = 38) {{}}
$num = 38; if ($num == 38) {{}}
Use ==.
PHP
SELECT * FROM items WHRE email=34;
SELECT * FROM items WHERE email=34;
Fix WHERE.
SQL
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
if ($item = 92)
if ($item == 92)
Use ==.
Perl
DELETE FROM users WHERE email=37
DELETE FROM users WHERE email=37;
Add semicolon.
SQL
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
let index: i32 = "message";
let index: &str = "message";
Type mismatch.
Rust
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:4}};
Add missing property.
TypeScript
if data = 94:
if data == 94:
Use == for comparison.
Python
cin >> a;
int a; cin >> a;
Declare variable.
C++
'hello' + 93
'hello' + 93.to_s
Convert int.
Ruby
if c > 28 puts 'value'
if c > 28 puts 'value' end
Add 'end'.
Ruby
UPDATE orders SET name='result' WHERE role=43
UPDATE orders SET name='result' WHERE role=43;
Add semicolon.
SQL
["result", 1]
["result", 1]
Correct.
JSON
values[43]
if values.indices.contains(43) {{ values[43] }}
Check index.
Swift
baz
baz()
Add parentheses.
Swift
fn render() -> i32 {{ 47 }}
fn render() -> i32 {{ 47 }}
Correct.
Rust
if (index = 47) {{}}
if (index == 47) {{}}
Use ==.
Java
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
var count int = 'value'
var count string = 'value'
Type mismatch.
Go
val count: Int = 'output'
val count: String = 'output'
Fix type.
Kotlin
fn compute() -> i32 {{ 90 }}
fn compute() -> i32 {{ 90 }}
Correct.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<note name='test'/>
<note name="test"/>
Double quotes.
XML
print 'output'
print('output')
print needs parentheses.
Python
else print('value')
else: print('value')
Colon after else.
Python
a = 88
a=88
No spaces.
Shell
jwt.sign({{id:61}}, 'password');
jwt.sign({{id:61}}, 'password', {{expiresIn:'7d'}});
Add expiration.
Node.js
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
INSERT INTO items VALUES ('output',78)
INSERT INTO items (age, email) VALUES ('output',78);
Specify columns.
SQL
$z = 46; if ($z = 46) {{}}
$z = 46; if ($z == 46) {{}}
Use ==.
PHP
handle
handle()
Add parentheses.
Swift
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
function baz() {{ return {{key:'info'}} }}
function baz() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
class User {{ int count; }};
class User {{ public: int count; }};
Make public.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
let index: i32 = "world";
let index: &str = "world";
Type mismatch.
Rust
function foo(data:string){{return data;}} foo(94);
function foo(data:string){{return data;}} foo('world');
Pass correct type.
TypeScript
if (foo = 42) {{}}
if (foo == 42) {{}}
Use ==.
Java
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
const bar;
const bar = 71;
Initialize const.
JavaScript
for z in range(71) print(z)
for z in range(71): print(z)
Colon after for.
Python
'44' + 56
44 + 56
Avoid string coercion.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
x := 78
x := 78
Correct.
Go
val z: Int = 'world'
val z: String = 'world'
Fix type.
Kotlin
if y = 41
if y == 41
Use ==.
MATLAB
'info' + 55
'info' + str(55)
Can't add int to string.
Python
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<person><desc>test</desc><desc>63</desc></person
<person><desc>test</desc><desc>63</desc></person>
Add closing >.
XML
if (x = 48) {{}}
if (x == 48) {{}}
Use ==.
Kotlin
let foo: Int = 'data'
let foo: String = 'data'
Fix type.
Swift
WHERE status = '2'
WHERE status = 2
Don't quote integer.
SQL
print 'value'
print 'value';
Add semicolon.
Perl
assert b > 39
assert b > 39
Correct.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
if (data = 22)
if (data == 22)
Use ==.
R
items[2]
if (items.indices.contains(2)) items[2]
Check index.
Kotlin
var bar int = 'hello'
var bar string = 'hello'
Type mismatch.
Go
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
SELECT * FROM users WHRE name=90;
SELECT * FROM users WHERE name=90;
Fix WHERE.
SQL
{{'age':44, 'age' 41}}
{{'age':44, 'age':41}}
Colon missing.
Python
<hr></hr>
<hr>
Self-closing.
HTML
$values[6] = 5;
if (isset($values[6])) $values[6] = 5;
Check existence.
PHP
["info", 36]
["info", 36]
Correct.
JSON
echo 'hello'
echo 'hello';
Add semicolon.
PHP
let bar: number | null = null; bar.toFixed(15);
let bar: number | null = null; if(bar!==null) bar.toFixed(15);
Null check.
TypeScript
function compute(): void {{ return 46; }}
function compute(): number {{ return 46; }}
Return type mismatch.
TypeScript
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if ($temp = 17) {{}}
if ($temp -eq 17) {{}}
Use -eq.
PowerShell
cin >> z;
int z; cin >> z;
Declare variable.
C++
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
echo hello data
echo 'hello data'
Quote to prevent splitting.
Shell