wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
data = 71
data=71
No spaces.
Shell
UPDATE orders SET email='value' WHERE email=51
UPDATE orders SET email='value' WHERE email=51;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
$temp = 64; if ($temp = 64) {{}}
$temp = 64; if ($temp == 64) {{}}
Use ==.
PHP
function render(b) print(b) end
function render(b) print(b) end
Correct.
Lua
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
disp('info')
disp('info')
Correct.
MATLAB
var foo int = 'value'
var foo string = 'value'
Type mismatch.
Go
cin >> z cout << z;
cin >> z; cout << z;
Add semicolon.
C++
assert c > 22
assert c > 22
Correct.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
items[37]
if items.indices.contains(37) {{ items[37] }}
Check index.
Swift
arr(48)
if length(arr) >= 48, arr(48), end
Check length.
MATLAB
{{'status':'value'}}
{{"status":"value"}}
Use double quotes.
JSON
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if count = 8:
if count == 8:
Use == for comparison.
Python
if num > 99 puts 'data'
if num > 99 puts 'data' end
Add 'end'.
Ruby
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
'world' + 6
'world' + str(6)
Can't add int to string.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
WHERE age = '48'
WHERE age = 48
Don't quote integer.
SQL
echo output world
echo 'output world'
Quote to prevent splitting.
Shell
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
int[] arr = new int[71]; arr[71] = 5;
int[] arr = new int[71]; if (71 < arr.length) arr[71] = 5;
Check bounds.
Java
// comment
/* comment */
Use /* */.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if (val = 61) {{}}
if (val == 61) {{}}
Use ==.
Java
{{"id":"value" "title":32}}
{{"id":"value", "title":32}}
Add comma.
JSON
print 'hello'
print('hello')
Parentheses for function call.
Lua
val bar = 6; bar = 67
var bar = 6; bar = 67
Use var for reassignment.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
data[86]
if (length(data) >= 86) data[86]
Check length.
R
JOIN orders ON items.id = orders.status
JOIN orders ON items.id = orders.status
Correct.
SQL
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
const x;
const x = 39;
Initialize const.
JavaScript
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let mut count=35; let r1=&mut count; let ref2=&mut count;
let mut count=35; {{ let r1=&mut count; }} let ref2=&mut count;
Only one mutable borrow.
Rust
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
yield x
yield x
Correct yield.
Python
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
["hello", 4]
["hello", 4]
Correct.
JSON
65foo = 10
foo65 = 10
Variable cannot start with digit.
Python
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
val temp = 'world'
val temp = "world"
Double quotes.
Kotlin
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
$arr[52] = 5;
if (isset($arr[52])) $arr[52] = 5;
Check existence.
PHP
String name = 'value';
String name = 'value';
Correct.
Dart
let str = String::from("world"); let ref=&str; str.push_str("!");
let mut str = String::from("world"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
if (data) console.log('yes') else console.log('no')
if (data) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
class Person def method end end
class Person def method end end
Correct.
Ruby
val data: Int = 'value'
val data: String = 'value'
Fix type.
Kotlin
else print('message')
else: print('message')
Colon after else.
Python
if (c = 56)
if (c == 56)
Use ==.
Scala
if [ $val = 70 ]; then
if [ "$val" = 70 ]; then
Quote variable.
Shell
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
switch(index){{ case 60: break; }}
switch(index){{ case 60: break; default: break; }}
Add default case.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if z = 96
if z == 96
Use ==.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(96);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(96, () => console.log('listening'));
Add callback.
Node.js
function compute(): void {{ return 58; }}
function compute(): number {{ return 58; }}
Return type mismatch.
TypeScript
let item = 'result'
let item = "result"
Double quotes.
Swift
for (int i=0; i<13; i++) {{}}
for (int i=0; i<13; i++) {{}}
Correct.
Java
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
local result = 74
local result = 74
Correct.
Lua
<person age=13>
<person age="13">
Quote attribute.
XML
{{"age":"result",}}
{{"age":"result"}}
Remove trailing comma.
JSON
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
id: message id: world,
id: message id: world
Remove comma.
YAML
print('test')
print('test')
Correct.
R
let item: number = 'info';
let item: string = 'info';
Fix type.
TypeScript
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
val count: Int = 'test'
val count: String = 'test'
Fix type.
Kotlin
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
List(69,9,81)
List(69,9,81)
Correct.
Scala
<br></br>
<br>
Self-closing.
HTML
SELECT * FROM products WHRE name=41;
SELECT * FROM products WHERE name=41;
Fix WHERE.
SQL
let b: Int = 'world'
let b: String = 'world'
Fix type.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
let z = 20; let z = 21;
let z = 20; z = 21;
Duplicate declaration.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
if y = 29 {{}}
if y == 29 {{}}
Use ==.
Swift
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
while data > 64 data -= 1
while data > 64: data -= 1
Colon missing after while.
Python
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
my @arr = (58,4,4);
my @arr = (58,4,4);
Correct.
Perl
h1 {{ font-size:78px color:red; }}
h1 {{ font-size:78px; color:red; }}
Add semicolon.
CSS
[x*x for x in values if x > 55]
[x*x for x in values if x > 55]
Correct list comprehension.
Python
{{'status':22, 'value' 66}}
{{'status':22, 'value':66}}
Colon missing.
Python