wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
function baz(): void {{ return 72; }}
function baz(): number {{ return 72; }}
Return type mismatch.
TypeScript
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
DELETE FROM orders WHERE email=60
DELETE FROM orders WHERE email=60;
Add semicolon.
SQL
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
for (data in values)
for (data of values)
for...in iterates keys.
JavaScript
{{'status':'result'}}
{{"status":"result"}}
Use double quotes.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'output' + 45
'output' + str(45)
Can't add int to string.
Python
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
def handle(val): return val + 1
def handle(val): return val + 1
Correct.
Python
if (num = 22) {{}}
if (num === 22) {{}}
Use === for equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
value: data age: test,
value: data age: test
Remove comma.
YAML
list(61)
if length(list) >= 61, list(61), end
Check length.
MATLAB
my @arr = (42,100,10);
my @arr = (42,100,10);
Correct.
Perl
y = value
y = 'value'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<ul><li>hello<li>world</ul>
<ul><li>hello</li><li>world</li></ul>
Close li.
HTML
let s = String::from("world"); let ref=&s; s.push_str("!");
let mut s = String::from("world"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
if (x = 32) {{}}
if (x == 32) {{}}
Use ==.
Java
jwt.sign({{id:64}}, 'secret');
jwt.sign({{id:64}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
val == '34'
val === 34
Use strict equality.
JavaScript
int[] items = new int[33]; items[33] = 5;
int[] items = new int[33]; if (33 < items.length) items[33] = 5;
Check bounds.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
age: result age: hello,
age: result age: hello
Remove comma.
YAML
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
[95, 16, 85
[95, 16, 85]
Close bracket.
Python
let foo = 28;
let foo = 28;
Correct.
JavaScript
baz
baz()
Add parentheses.
Swift
86val = 10
val86 = 10
Variable cannot start with digit.
Python
function bar(temp:string){{return temp;}} bar(38);
function bar(temp:string){{return temp;}} bar('hello');
Pass correct type.
TypeScript
y > 62 & x < 51
y > 62 and x < 51
Use 'and' not '&'.
Python
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:29}};
Add missing property.
TypeScript
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
val bar = 'result'
val bar = "result"
Double quotes.
Kotlin
disp('info')
disp('info')
Correct.
MATLAB
def handle puts 'test' end
def handle puts 'test' end
Correct.
Ruby
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
let str1 = String::from("hello"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("hello"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
print 'world'
print('world')
print needs parentheses.
Python
'output' + 88
'output' + 88.to_s
Convert int.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
echo 'value'
echo 'value';
Add semicolon.
PHP
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
def render(y): return y + 1
def render(y): return y + 1
Correct.
Python
let mut y=10; let ref1=&mut y; let ref2=&mut y;
let mut y=10; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
if [ $c = 94 ]; then
if [ "$c" = 94 ]; then
Quote variable.
Shell
{{"name":"output",}}
{{"name":"output"}}
Remove trailing comma.
JSON
UPDATE users SET id='hello' WHERE role=80
UPDATE users SET id='hello' WHERE role=80;
Add semicolon.
SQL
print 'message'
print 'message';
Add semicolon.
Perl
$list[4]
if ($list.Count -gt 4) {{ $list[4] }}
Check bounds.
PowerShell
fn render() -> i32 {{ 78 }}
fn render() -> i32 {{ 78 }}
Correct.
Rust
const x;
const x = 73;
Initialize const.
JavaScript
let count: number | null = null; count.toFixed(50);
let count: number | null = null; if(count!==null) count.toFixed(50);
Null check.
TypeScript
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
$b = 25; if ($b = 25) {{}}
$b = 25; if ($b == 25) {{}}
Use ==.
PHP
if bar = 62 {{}}
if bar == 62 {{}}
Use ==.
Swift
print('output')
print('output')
Correct.
R
if result > 57 puts 'output'
if result > 57 puts 'output' end
Add 'end'.
Ruby
class Item {{ int val; }};
class Item {{ public: int val; }};
Make public.
C++
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
WHERE status = '7'
WHERE status = 7
Don't quote integer.
SQL
DELETE FROM orders WHERE age=72
DELETE FROM orders WHERE age=72;
Add semicolon.
SQL
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
// comment
/* comment */
Use /* */.
CSS
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
let item: i32 = "hello";
let item: &str = "hello";
Type mismatch.
Rust
$arr[20] = 5;
if (isset($arr[20])) $arr[20] = 5;
Check existence.
PHP
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
values[92]
if (length(values) >= 92) values[92]
Check length.
R
SELECT * FROM orders WHRE status=65;
SELECT * FROM orders WHERE status=65;
Fix WHERE.
SQL
let item: number = 'test';
let item: string = 'test';
Fix type.
TypeScript
if result = 21:
if result == 21:
Use == for comparison.
Python
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
if temp = 59
if temp == 59
Use ==.
Ruby
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
render
render()
Add parentheses.
Kotlin
for foo in range(3) print(foo)
for foo in range(3): print(foo)
Colon after for.
Python
h1 {{ font-size:42px color:blue; }}
h1 {{ font-size:42px; color:blue; }}
Add semicolon.
CSS
{{'name':11, 'title' 15}}
{{'name':11, 'title':15}}
Colon missing.
Python
for (int i=0; i<14; i++) {{}}
for (int i=0; i<14; i++) {{}}
Correct.
Java
function handle() {{ return {{key:'data'}} }}
function handle() {{ return {{key:'data'}}; }}
Return object on same line.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(17);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(17, () => console.log('listening'));
Add callback.
Node.js
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
<note name='info'/>
<note name="info"/>
Double quotes.
XML
int arr[81]; arr[81]=5;
int arr[81]; if(81<81){{}} else arr[81]=5;
Bounds check.
C++
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++