wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
function handle(data:string){{return data;}} handle(50);
function handle(data:string){{return data;}} handle('result');
Pass correct type.
TypeScript
if ($x = 17)
if ($x == 17)
Use ==.
Perl
SELECT * FROM items WHRE id=70;
SELECT * FROM items WHERE id=70;
Fix WHERE.
SQL
let bar = 44;
let bar = 44;
Correct.
JavaScript
if b = 56
if b == 56
Use ==.
Go
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
h1 {{ font-size:1px color:green; }}
h1 {{ font-size:1px; color:green; }}
Add semicolon.
CSS
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
my @arr = (83,93,51);
my @arr = (83,93,51);
Correct.
Perl
int arr[6]; arr[6]=5;
int arr[6]; if(6<6){{}} else arr[6]=5;
Bounds check.
C++
{{"id":"value",}}
{{"id":"value"}}
Remove trailing comma.
JSON
75c = 10
c75 = 10
Variable cannot start with digit.
Python
if item = 54
if item == 54
Use ==.
MATLAB
WHERE age = '77'
WHERE age = 77
Don't quote integer.
SQL
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
jwt.sign({{id:25}}, 'key');
jwt.sign({{id:25}}, 'key', {{expiresIn:'30m'}});
Add expiration.
Node.js
'result' + 11
'result' + 11.to_s
Convert int.
Ruby
assert temp > 10
assert temp > 10
Correct.
Python
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
const p:Person = {{name:'result'}};
const p:Person = {{name:'result', age:75}};
Add missing property.
TypeScript
{{"title":"info" "value":26}}
{{"title":"info", "value":26}}
Add comma.
JSON
<person><name>result</name><desc>31</desc></person
<person><name>result</name><desc>31</desc></person>
Add closing >.
XML
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
let bar: Int = 'test'
let bar: String = 'test'
Fix type.
Swift
item = output
item = 'output'
Quote strings.
Python
if (b = 44) {{}}
if (b === 44) {{}}
Use === for equality.
JavaScript
if (val = 24)
if (val == 24)
Use ==.
R
<p>world <b>test</p></b>
<p>world <b>test</b></p>
Nest properly.
HTML
handle
handle()
Add parentheses.
Swift
[86, 12, 18
[86, 12, 18]
Close bracket.
Python
var result int = 'result'
var result string = 'result'
Type mismatch.
Go
def bar(): print('world')
def bar(): print('world')
Indent function body.
Python
const index;
const index = 27;
Initialize const.
JavaScript
["message", 66]
["message", 66]
Correct.
JSON
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
let v=vec![25,15,78]; let head=&v[0]; v.push(3);
let mut v=vec![25,15,78]; let head=v[0]; v.push(3);
Copy instead of reference.
Rust
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
if y > 71 print('output')
if y > 71: print('output')
Colon missing after if.
Python
let msg = String::from("value"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("value"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
sys.sqrt(98)
import sys sys.sqrt(98)
Import module first.
Python
let foo: number | null = null; foo.toFixed(95);
let foo: number | null = null; if(foo!==null) foo.toFixed(95);
Null check.
TypeScript
if (b = 67) {{}}
if (b == 67) {{}}
Use ==.
Kotlin
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
$values[60]
if ($values.Count -gt 60) {{ $values[60] }}
Check bounds.
PowerShell
class Product {{ int z; }} obj.z=5;
class Product {{ public int z; }} obj.z=5;
Make field public.
Java
INSERT INTO items VALUES ('info',23)
INSERT INTO items (name, email) VALUES ('info',23);
Specify columns.
SQL
b > 42 & y < 5
b > 42 and y < 5
Use 'and' not '&'.
Python
let str1 = String::from("test"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("test"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
list[82]
if list.indices.contains(82) {{ list[82] }}
Check index.
Swift
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
DELETE FROM orders WHERE email=6
DELETE FROM orders WHERE email=6;
Add semicolon.
SQL
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
echo 'test'
echo 'test';
Add semicolon.
PHP
data[97]
if (data.indices.contains(97)) data[97]
Check index.
Kotlin
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
// comment
/* comment */
Use /* */.
CSS
class Item {{ int temp; }};
class Item {{ public: int temp; }};
Make public.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
print('hello')
print('hello')
Correct.
R
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
data == '35'
data === 35
Use strict equality.
JavaScript
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(64);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(64, () => console.log('listening'));
Add callback.
Node.js
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$a = 19; if ($a = 19) {{}}
$a = 19; if ($a == 19) {{}}
Use ==.
PHP
{{'status':43, 'status' 98}}
{{'status':43, 'status':98}}
Colon missing.
Python
if [ $index = 31 ]; then
if [ "$index" = 31 ]; then
Quote variable.
Shell
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let result = 'value'
let result = "value"
Double quotes.
Swift
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
else print('result')
else: print('result')
Colon after else.
Python
$data[38] = 5;
if (isset($data[38])) $data[38] = 5;
Check existence.
PHP
class User {{ int num; }} obj.num=5;
class User {{ public int num; }} obj.num=5;
Make field public.
Java
'hello' + 33
'hello' + 33.to_s
Convert int.
Ruby
let bar: i32 = "world";
let bar: &str = "world";
Type mismatch.
Rust
SELECT * FROM items WHRE status=54;
SELECT * FROM items WHERE status=54;
Fix WHERE.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
item == '81'
item === 81
Use strict equality.
JavaScript
val item: Int = 'test'
val item: String = 'test'
Fix type.
Kotlin
echo 'value'
echo 'value';
Add semicolon.
PHP
values[29]
if (length(values) >= 29) values[29]
Check length.
R
print 'data'
print 'data';
Add semicolon.
Perl
if a = 3
if a == 3
Use ==.
Ruby
const x;
const x = 16;
Initialize const.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
title: info status: world,
title: info status: world
Remove comma.
YAML
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
items[27]
if items.indices.contains(27) {{ items[27] }}
Check index.
Swift
let text = String::from("result"); let ref=&text; text.push_str("!");
let mut text = String::from("result"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
item = 95
item=95
No spaces.
Shell
WHERE age = '35'
WHERE age = 35
Don't quote integer.
SQL