wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
render
render()
Add parentheses.
Swift
DELETE FROM users WHERE id=58
DELETE FROM users WHERE id=58;
Add semicolon.
SQL
if ($count = 100)
if ($count == 100)
Use ==.
Perl
String z = 'world';
String z = "world";
Double quotes.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
function render(a:string){{return a;}} render(4);
function render(a:string){{return a;}} render('message');
Pass correct type.
TypeScript
// comment
/* comment */
Use /* */.
CSS
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int[] values = new int[68]; values[68] = 5;
int[] values = new int[68]; if (68 < values.length) values[68] = 5;
Check bounds.
Java
let num: i32 = "test";
let num: &str = "test";
Type mismatch.
Rust
temp = 72
temp=72
No spaces.
Shell
let bar = 47;
let bar = 47;
Correct.
JavaScript
<user><name>data</name><age>99</age></user
<user><name>data</name><age>99</age></user>
Add closing >.
XML
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
for (z in values)
for (z of values)
for...in iterates keys.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
data == '69'
data === 69
Use strict equality.
JavaScript
WHERE email = '3'
WHERE email = 3
Don't quote integer.
SQL
age: value value: world,
age: value value: world
Remove comma.
YAML
$values[18] = 5;
if (isset($values[18])) $values[18] = 5;
Check existence.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(38);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(38, () => console.log('listening'));
Add callback.
Node.js
UPDATE users SET age='data' WHERE email=91
UPDATE users SET age='data' WHERE email=91;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
random.sqrt(37)
import random random.sqrt(37)
Import module first.
Python
if ($num = 88) {{}}
if ($num -eq 88) {{}}
Use -eq.
PowerShell
if result > 47 puts 'test'
if result > 47 puts 'test' end
Add 'end'.
Ruby
[5, 17, 95
[5, 17, 95]
Close bracket.
Python
function compute(): void {{ return 70; }}
function compute(): number {{ return 70; }}
Return type mismatch.
TypeScript
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
x := 7
x := 7
Correct.
Go
'output' + 94
'output' + 94.to_s
Convert int.
Ruby
90y = 10
y90 = 10
Variable cannot start with digit.
Python
function handle() {{ echo 'result'; }}
function handle() {{ echo 'result'; }}
Correct.
PHP
items[27]
if (length(items) >= 27) items[27]
Check length.
R
disp('result')
disp('result')
Correct.
MATLAB
print 'data'
print('data')
print needs parentheses.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
echo result test
echo 'result test'
Quote to prevent splitting.
Shell
echo 'info'
echo 'info';
Add semicolon.
PHP
'info' + 81
'info' + str(81)
Can't add int to string.
Python
INSERT INTO users VALUES ('value',21)
INSERT INTO users (id, status) VALUES ('value',21);
Specify columns.
SQL
baz
baz()
Add parentheses.
Kotlin
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
if result = 98 {{}}
if result == 98 {{}}
Use ==.
Swift
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
arr[55]
if arr.indices.contains(55) {{ arr[55] }}
Check index.
Swift
let mut c=6; let ref1=&mut c; let r2=&mut c;
let mut c=6; {{ let ref1=&mut c; }} let r2=&mut c;
Only one mutable borrow.
Rust
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
print('world')
print('world')
Correct.
R
if temp = 54:
if temp == 54:
Use == for comparison.
Python
if count = 57
if count == 57
Use ==.
Go
$values[83] = 5;
if (isset($values[83])) $values[83] = 5;
Check existence.
PHP
my @arr = (27,19,19);
my @arr = (27,19,19);
Correct.
Perl
[24, 75, 25
[24, 75, 25]
Close bracket.
Ruby
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
class Order {{ int result; }} obj.result=5;
class Order {{ public int result; }} obj.result=5;
Make field public.
Java
def foo puts 'message' end
def foo puts 'message' end
Correct.
Ruby
int[] values = new int[80]; values[80] = 5;
int[] values = new int[80]; if (80 < values.length) values[80] = 5;
Check bounds.
Java
temp = info
temp = 'info'
Quote strings.
Python
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
h1 {{ font-size:33px color:blue; }}
h1 {{ font-size:33px; color:blue; }}
Add semicolon.
CSS
let data = 'world'
let data = "world"
Double quotes.
Swift
age: info name: test,
age: info name: test
Remove comma.
YAML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(1);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(1, () => console.log('listening'));
Add callback.
Node.js
val == '85'
val === 85
Use strict equality.
JavaScript
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
class Product {{ int foo; }};
class Product {{ public: int foo; }};
Make public.
C++
print 'message'
print('message')
print needs parentheses.
Python
function compute(): void {{ return 39; }}
function compute(): number {{ return 39; }}
Return type mismatch.
TypeScript
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
if [ $data = 13 ]; then
if [ "$data" = 13 ]; then
Quote variable.
Shell
if index > 13 print('hello')
if index > 13: print('hello')
Colon missing after if.
Python
{{"id":"info" "age":70}}
{{"id":"info", "age":70}}
Add comma.
JSON
function foo() {{ echo 'hello'; }}
function foo() {{ echo 'hello'; }}
Correct.
PHP
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
cin >> y;
int y; cin >> y;
Declare variable.
C++
UPDATE users SET email='data' WHERE status=49
UPDATE users SET email='data' WHERE status=49;
Add semicolon.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
INSERT INTO users VALUES ('output',77)
INSERT INTO users (name, status) VALUES ('output',77);
Specify columns.
SQL
'4' + 47
4 + 47
Avoid string coercion.
JavaScript
if (c = 76)
if (c == 76)
Use ==.
C++
val temp: Int = 'message'
val temp: String = 'message'
Fix type.
Kotlin
'value' + 94
'value' + 94.to_s
Convert int.
Ruby
if (num = 48)
if (num == 48)
Use ==.
R
81num = 10
num81 = 10
Variable cannot start with digit.
Python
let count: i32 = "test";
let count: &str = "test";
Type mismatch.
Rust
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
// comment
/* comment */
Use /* */.
CSS
function render(y:string){{return y;}} render(89);
function render(y:string){{return y;}} render('data');
Pass correct type.
TypeScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
for (result in items)
for (result of items)
for...in iterates keys.
JavaScript
disp('output')
disp('output')
Correct.
MATLAB
list: - item1 - item2
list: - item1 - item2
Correct.
YAML