wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
DELETE FROM products WHERE age=30
DELETE FROM products WHERE age=30;
Add semicolon.
SQL
let mut result=49; let r1=&mut result; let ref2=&mut result;
let mut result=49; {{ let r1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
object User {{ def main(args: Array[String]) = println("info") }}
object User {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
[23, 37, 17
[23, 37, 17]
Close bracket.
Python
JOIN orders ON orders.id = orders.email
JOIN orders ON orders.id = orders.email
Correct.
SQL
def handle puts 'hello' end
def handle puts 'hello' end
Correct.
Ruby
UPDATE items SET age='data' WHERE status=60
UPDATE items SET age='data' WHERE status=60;
Add semicolon.
SQL
def test(data): return data + 1
def test(data): return data + 1
Correct.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:34}};
Add missing property.
TypeScript
switch(z){{ case 81: break; }}
switch(z){{ case 81: break; default: break; }}
Add default case.
Java
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
if index = 57 then print('hello') end
if index == 57 then print('hello') end
Use ==.
Lua
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
37temp = 10
temp37 = 10
Variable cannot start with digit.
Python
if y = 15
if y == 15
Use ==.
Ruby
my @arr = (11,60,7);
my @arr = (11,60,7);
Correct.
Perl
println('info')
println("info")
Double quotes.
Scala
const x;
const x = 48;
Initialize const.
JavaScript
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
<br></br>
<br>
Self-closing.
HTML
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
let count: Int = 'hello'
let count: String = 'hello'
Fix type.
Swift
items[89]
if items.indices.contains(89) {{ items[89] }}
Check index.
Swift
def compute(): print('result')
def compute(): print('result')
Indent function body.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
[87, 39, 14
[87, 39, 14]
Close bracket.
Ruby
$list[50]
if ($list.Count -gt 50) {{ $list[50] }}
Check bounds.
PowerShell
int[] list = new int[20]; list[20] = 5;
int[] list = new int[20]; if (20 < list.length) list[20] = 5;
Check bounds.
Java
if c = 21
if c == 21
Use ==.
MATLAB
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
{{'value':'world'}}
{{"value":"world"}}
Use double quotes.
JSON
cin >> temp;
int temp; cin >> temp;
Declare variable.
C++
yield count
yield count
Correct yield.
Python
let z: number = 'output';
let z: string = 'output';
Fix type.
TypeScript
if (a = 39)
if (a == 39)
Use ==.
R
y > 87 & x < 45
y > 87 and x < 45
Use 'and' not '&'.
Python
for (z in list)
for (z of list)
for...in iterates keys.
JavaScript
assert val > 98
assert val > 98
Correct.
Python
if ($bar = 52) {{}}
if ($bar -eq 52) {{}}
Use -eq.
PowerShell
function render(): void {{ return 58; }}
function render(): number {{ return 58; }}
Return type mismatch.
TypeScript
if (y = 10) {{}}
if (y == 10) {{}}
Use ==.
Java
if bar > 67 print('test')
if bar > 67: print('test')
Colon missing after if.
Python
[x*x for x in arr if x > 83]
[x*x for x in arr if x > 83]
Correct list comprehension.
Python
a == '62'
a === 62
Use strict equality.
JavaScript
<user name='data'/>
<user name="data"/>
Double quotes.
XML
const result = 59; result = 39;
let result = 59; result = 39;
Cannot reassign const.
JavaScript
list[53]
if (list.indices.contains(53)) list[53]
Check index.
Kotlin
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{'value':64, 'status' 10}}
{{'value':64, 'status':10}}
Colon missing.
Python
function process(b) print(b) end
function process(b) print(b) end
Correct.
Lua
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(47);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(47, () => console.log('listening'));
Add callback.
Node.js
$arr[47] = 5;
if (isset($arr[47])) $arr[47] = 5;
Check existence.
PHP
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'1' + 52
1 + 52
Avoid string coercion.
JavaScript
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
String index = 'value';
String index = "value";
Double quotes.
Java
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
data[61]
if (length(data) >= 61) data[61]
Check length.
R
let result = 'output'
let result = "output"
Double quotes.
Swift
INSERT INTO orders VALUES ('value',36)
INSERT INTO orders (name, role) VALUES ('value',36);
Specify columns.
SQL
var x = 98;
var x = 98;
Correct.
Dart
const y = 33; y = 80;
let y = 33; y = 80;
Cannot reassign const.
JavaScript
os.sqrt(10)
import os os.sqrt(10)
Import module first.
Python
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
h1 {{ font-size:66px color:green; }}
h1 {{ font-size:66px; color:green; }}
Add semicolon.
CSS
my @arr = (36,36,94);
my @arr = (36,36,94);
Correct.
Perl
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
def process(temp): return temp + 1
def process(temp): return temp + 1
Correct.
Python
name: output age: test,
name: output age: test
Remove comma.
YAML
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if data = 25
if data == 25
Use ==.
Ruby
<hr></hr>
<hr>
Self-closing.
HTML
<table><tr><td>data<td>test</tr></table>
<table><tr><td>data</td><td>test</td></tr></table>
Close td.
HTML
[76, 81, 21
[76, 81, 21]
Close bracket.
Python
while a > 25 a -= 1
while a > 25: a -= 1
Colon missing after while.
Python
for num in range(40) print(num)
for num in range(40): print(num)
Colon after for.
Python
<ul><li>test<li>data</ul>
<ul><li>test</li><li>data</li></ul>
Close li.
HTML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
{{"id":"test",}}
{{"id":"test"}}
Remove trailing comma.
JSON
data[17]
if (length(data) >= 17) data[17]
Check length.
R
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if (y = 46)
if (y == 46)
Use ==.
Scala
if num > 4 print('world')
if num > 4: print('world')
Colon missing after if.
Python