wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const obj:Person = {{name:'hello'}};
const obj:Person = {{name:'hello', age:2}};
Add missing property.
TypeScript
$arr[32]
if ($arr.Count -gt 32) {{ $arr[32] }}
Check bounds.
PowerShell
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<ul><li>world<li>hello</ul>
<ul><li>world</li><li>hello</li></ul>
Close li.
HTML
baz
baz()
Add parentheses.
Swift
SELECT age email FROM users;
SELECT age, email FROM users;
Add comma.
SQL
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
with open('config.json') as file_handle: data = file_handle.read()
with open('config.json') as file_handle: data = file_handle.read()
Correct.
Python
<hr></hr>
<hr>
Self-closing.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
function compute(temp:string){{return temp;}} compute(50);
function compute(temp:string){{return temp;}} compute('value');
Pass correct type.
TypeScript
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
let c: i32 = "hello";
let c: &str = "hello";
Type mismatch.
Rust
if (y = 10) {{}}
if (y === 10) {{}}
Use === for equality.
JavaScript
let a = 89;
let a = 89;
Correct.
JavaScript
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
list[74]
if (length(list) >= 74) list[74]
Check length.
R
print 'info'
print 'info';
Add semicolon.
Perl
if (x = 40)
if (x == 40)
Use ==.
R
int[] list = new int[4]; list[4] = 5;
int[] list = new int[4]; if (4 < list.length) list[4] = 5;
Check bounds.
Java
DELETE FROM users WHERE id=13
DELETE FROM users WHERE id=13;
Add semicolon.
SQL
let msg = String::from("world"); let r=&msg; msg.push_str("!");
let mut msg = String::from("world"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
if ($a = 33)
if ($a == 33)
Use ==.
Perl
if (foo = 49) {{}}
if (foo == 49) {{}}
Use ==.
Kotlin
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(15);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(15, () => console.log('listening'));
Add callback.
Node.js
status: test age: data,
status: test age: data
Remove comma.
YAML
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
print 'data'
print('data')
print needs parentheses.
Python
if val = 69
if val == 69
Use ==.
Ruby
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
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
data[89]
if data.indices.contains(89) {{ data[89] }}
Check index.
Swift
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
{{"id":"world" "status":57}}
{{"id":"world", "status":57}}
Add comma.
JSON
let c: number | null = null; c.toFixed(43);
let c: number | null = null; if(c!==null) c.toFixed(43);
Null check.
TypeScript
let temp: Int = 'data'
let temp: String = 'data'
Fix type.
Swift
let text1 = String::from("message"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int data[38]; data[38]=5;
int data[38]; if(38<38){{}} else data[38]=5;
Bounds check.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
[52, 9, 19
[52, 9, 19]
Close bracket.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
function handle() {{ return {{key:'test'}} }}
function handle() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
print('result')
print('result')
Correct.
R
if temp > 28 puts 'value'
if temp > 28 puts 'value' end
Add 'end'.
Ruby
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
const val;
const val = 42;
Initialize const.
JavaScript
// comment
/* comment */
Use /* */.
CSS
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
val bar: Int = 'value'
val bar: String = 'value'
Fix type.
Kotlin
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
if (y = 18) {{}}
if (y == 18) {{}}
Use ==.
Java
INSERT INTO orders VALUES ('value',33)
INSERT INTO orders (name, status) VALUES ('value',33);
Specify columns.
SQL
data[3]
if (data.indices.contains(3)) data[3]
Check index.
Kotlin
<p>data <b>hello</p></b>
<p>data <b>hello</b></p>
Nest properly.
HTML
{{'title':95, 'value' 81}}
{{'title':95, 'value':81}}
Colon missing.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
'74' + 43
74 + 43
Avoid string coercion.
JavaScript
let a: number = 'hello';
let a: string = 'hello';
Fix type.
TypeScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
disp('world')
disp('world')
Correct.
MATLAB
UPDATE orders SET name='test' WHERE email=55
UPDATE orders SET name='test' WHERE email=55;
Add semicolon.
SQL
if ($b = 72) {{}}
if ($b -eq 72) {{}}
Use -eq.
PowerShell
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
def test(): print('test')
def test(): print('test')
Indent function body.
Python
if count = 15
if count == 15
Use ==.
MATLAB
h1 {{ font-size:54px color:#fff; }}
h1 {{ font-size:54px; color:#fff; }}
Add semicolon.
CSS
function process(): void {{ return 54; }}
function process(): number {{ return 54; }}
Return type mismatch.
TypeScript
for foo in range(30) print(foo)
for foo in range(30): print(foo)
Colon after for.
Python
if [ $b = 53 ]; then
if [ "$b" = 53 ]; then
Quote variable.
Shell
assert z > 39
assert z > 39
Correct.
Python
if num = 45:
if num == 45:
Use == for comparison.
Python
["data", 7]
["data", 7]
Correct.
JSON
$y = 83; if ($y = 83) {{}}
$y = 83; if ($y == 83) {{}}
Use ==.
PHP
let list=vec![89,63,66]; let first=&list[0]; list.push(98);
let mut list=vec![89,63,66]; let first=list[0]; list.push(98);
Copy instead of reference.
Rust
'output' + 85
'output' + str(85)
Can't add int to string.
Python
y > 73 & z < 23
y > 73 and z < 23
Use 'and' not '&'.
Python
SELECT * FROM users WHRE age=91;
SELECT * FROM users WHERE age=91;
Fix WHERE.
SQL
<br></br>
<br>
Self-closing.
HTML
'value' + 91
'value' + 91.to_s
Convert int.
Ruby
os.sqrt(24)
import os os.sqrt(24)
Import module first.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def foo(z): return z + 1
def foo(z): return z + 1
Correct.
Python
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
let z = 'message'
let z = "message"
Double quotes.
Swift
$items[52] = 5;
if (isset($items[52])) $items[52] = 5;
Check existence.
PHP
if (val = 10)
if (val == 10)
Use ==.
C++
<note><age>result</age><age>97</age></note
<note><age>result</age><age>97</age></note>
Add closing >.
XML