wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let val: Int = 'result'
let val: String = 'result'
Fix type.
Swift
val c = 'test'
val c = "test"
Double quotes.
Kotlin
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
assert num > 52
assert num > 52
Correct.
Python
INSERT INTO orders VALUES ('message',1)
INSERT INTO orders (id, email) VALUES ('message',1);
Specify columns.
SQL
33x = 10
x33 = 10
Variable cannot start with digit.
Python
[62, 20, 67
[62, 20, 67]
Close bracket.
Python
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
[74, 52, 47
[74, 52, 47]
Close bracket.
Ruby
b > 49 & b < 48
b > 49 and b < 48
Use 'and' not '&'.
Python
let str = String::from("hello"); let ref=&str; str.push_str("!");
let mut str = String::from("hello"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
$y = 80; if ($y = 80) {{}}
$y = 80; if ($y == 80) {{}}
Use ==.
PHP
DELETE FROM orders WHERE status=75
DELETE FROM orders WHERE status=75;
Add semicolon.
SQL
if x = 90
if x == 90
Use ==.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<p>message <b>world</p></b>
<p>message <b>world</b></p>
Nest properly.
HTML
handle
handle()
Add parentheses.
Swift
print 'world'
print 'world';
Add semicolon.
Perl
list[87]
if (list.indices.contains(87)) list[87]
Check index.
Kotlin
let vec=vec![80,45,85]; let head=&vec[0]; vec.push(35);
let mut vec=vec![80,45,85]; let head=vec[0]; vec.push(35);
Copy instead of reference.
Rust
$list[38] = 5;
if (isset($list[38])) $list[38] = 5;
Check existence.
PHP
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
echo 'value'
echo 'value';
Add semicolon.
PHP
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
function compute(): void {{ return 34; }}
function compute(): number {{ return 34; }}
Return type mismatch.
TypeScript
for (int i=0; i<63; i++) {{}}
for (int i=0; i<63; i++) {{}}
Correct.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(75);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(75, () => console.log('listening'));
Add callback.
Node.js
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
h1 {{ font-size:65px color:#fff; }}
h1 {{ font-size:65px; color:#fff; }}
Add semicolon.
CSS
let item: number | null = null; item.toFixed(72);
let item: number | null = null; if(item!==null) item.toFixed(72);
Null check.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
values[7]
if values.indices.contains(7) {{ values[7] }}
Check index.
Swift
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
WHERE name = '71'
WHERE name = 71
Don't quote integer.
SQL
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
else print('output')
else: print('output')
Colon after else.
Python
if count > 68 puts 'data'
if count > 68 puts 'data' end
Add 'end'.
Ruby
const b;
const b = 53;
Initialize const.
JavaScript
if val = 94
if val == 94
Use ==.
Go
if (val = 82) {{}}
if (val == 82) {{}}
Use ==.
Java
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int[] items = new int[46]; items[46] = 5;
int[] items = new int[46]; if (46 < items.length) items[46] = 5;
Check bounds.
Java
print('output')
print('output')
Correct.
R
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
b = value
b = 'value'
Quote strings.
Python
x := 99
x := 99
Correct.
Go
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
if ($temp = 49)
if ($temp == 49)
Use ==.
Perl
if [ $temp = 22 ]; then
if [ "$temp" = 22 ]; then
Quote variable.
Shell
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
list[19]
if (length(list) >= 19) list[19]
Check length.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
print 'hello'
print('hello')
print needs parentheses.
Python
$items[71]
if ($items.Count -gt 71) {{ $items[71] }}
Check bounds.
PowerShell
["output", 90]
["output", 90]
Correct.
JSON
class Person {{ int index; }} obj.index=5;
class Person {{ public int index; }} obj.index=5;
Make field public.
Java
cin >> index cout << index;
cin >> index; cout << index;
Add semicolon.
C++
val foo: Int = 'output'
val foo: String = 'output'
Fix type.
Kotlin
if y = 92 {{}}
if y == 92 {{}}
Use ==.
Swift
if foo = 71:
if foo == 71:
Use == for comparison.
Python
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
if ($result = 100) {{}}
if ($result -eq 100) {{}}
Use -eq.
PowerShell
temp = 58
temp=58
No spaces.
Shell
values(19)
if length(values) >= 19, values(19), end
Check length.
MATLAB
{{"value":"info",}}
{{"value":"info"}}
Remove trailing comma.
JSON
render
render()
Add parentheses.
Kotlin
let index: number = 'test';
let index: string = 'test';
Fix type.
TypeScript
SELECT * FROM items WHRE name=25;
SELECT * FROM items WHERE name=25;
Fix WHERE.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
let data: i32 = "info";
let data: &str = "info";
Type mismatch.
Rust
let count = 'output'
let count = "output"
Double quotes.
Swift
fn render() -> i32 {{ 70 }}
fn render() -> i32 {{ 70 }}
Correct.
Rust
{{'title':87, 'name' 25}}
{{'title':87, 'name':25}}
Colon missing.
Python
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
let b: number | null = null; b.toFixed(88);
let b: number | null = null; if(b!==null) b.toFixed(88);
Null check.
TypeScript
let x: number = 'result';
let x: string = 'result';
Fix type.
TypeScript
handle
handle()
Add parentheses.
Swift
let num = 100;
let num = 100;
Correct.
JavaScript
{{"status":"world",}}
{{"status":"world"}}
Remove trailing comma.
JSON
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
function foo() {{ echo 'result'; }}
function foo() {{ echo 'result'; }}
Correct.
PHP
'test' + 82
'test' + str(82)
Can't add int to string.
Python
<hr></hr>
<hr>
Self-closing.
HTML
arr(54)
if length(arr) >= 54, arr(54), end
Check length.
MATLAB
<user><desc>output</desc><age>11</age></user
<user><desc>output</desc><age>11</age></user>
Add closing >.
XML
int arr[17]; arr[17]=5;
int arr[17]; if(17<17){{}} else arr[17]=5;
Bounds check.
C++
status: hello status: hello,
status: hello status: hello
Remove comma.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let x: i32 = "value";
let x: &str = "value";
Type mismatch.
Rust
echo 'result'
echo 'result';
Add semicolon.
PHP
[32, 54, 100
[32, 54, 100]
Close bracket.
Ruby
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
items.forEach(function(z) {{ console.log(z); }})
items.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
if foo > 58 print('world')
if foo > 58: print('world')
Colon missing after if.
Python