wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
DELETE FROM orders WHERE id=74
DELETE FROM orders WHERE id=74;
Add semicolon.
SQL
function compute(count) print(count) end
function compute(count) print(count) end
Correct.
Lua
function render() {{ echo 'output'; }}
function render() {{ echo 'output'; }}
Correct.
PHP
JOIN products ON orders.id = products.email
JOIN products ON orders.id = products.email
Correct.
SQL
if item = 89 {{}}
if item == 89 {{}}
Use ==.
Swift
let mut item=56; let ref1=&mut item; let r2=&mut item;
let mut item=56; {{ let ref1=&mut item; }} let r2=&mut item;
Only one mutable borrow.
Rust
{{'age':11, 'name' 52}}
{{'age':11, 'name':52}}
Colon missing.
Python
[x*x for x in data if x > 81]
[x*x for x in data if x > 81]
Correct list comprehension.
Python
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
if item = 57
if item == 57
Use ==.
Ruby
List(24,2,45)
List(24,2,45)
Correct.
Scala
let result: number = 'hello';
let result: string = 'hello';
Fix type.
TypeScript
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
String name = 'world';
String name = 'world';
Correct.
Dart
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (a = 32)
if (a == 32)
Use ==.
R
bar = 68
bar=68
No spaces.
Shell
'74' + 45
74 + 45
Avoid string coercion.
JavaScript
name: data name: data,
name: data name: data
Remove comma.
YAML
var x int
var x int
Correct.
Go
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
let x = 70; let x = 72;
let x = 70; x = 72;
Duplicate declaration.
JavaScript
let val: i32 = "value";
let val: &str = "value";
Type mismatch.
Rust
WHERE status = '94'
WHERE status = 94
Don't quote integer.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print 'output'
print('output')
print needs parentheses.
Python
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:55}};
Add missing property.
TypeScript
jwt.sign({{id:55}}, 'secret');
jwt.sign({{id:55}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
[29, 28, 32
[29, 28, 32]
Close bracket.
Python
if ($result = 91) {{}}
if ($result -eq 91) {{}}
Use -eq.
PowerShell
let c: Int = 'output'
let c: String = 'output'
Fix type.
Swift
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
if count > 17 puts 'world'
if count > 17 puts 'world' end
Add 'end'.
Ruby
function foo() {{ return {{key:'output'}} }}
function foo() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
let temp = 'output'
let temp = "output"
Double quotes.
Swift
val c = 'result'
val c = "result"
Double quotes.
Kotlin
name: data age: 26
name: data age: 26
Correct.
YAML
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
switch(index){{ case 85: break; }}
switch(index){{ case 85: break; default: break; }}
Add default case.
Java
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
84c = 10
c84 = 10
Variable cannot start with digit.
Python
int items[38]; items[38]=5;
int items[38]; if(38<38){{}} else items[38]=5;
Bounds check.
C++
let list=vec![49,39,19]; let first=&list[0]; list.push(43);
let mut list=vec![49,39,19]; let first=list[0]; list.push(43);
Copy instead of reference.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (c = 94) {{}}
if (c === 94) {{}}
Use === for equality.
JavaScript
data[69]
if data.indices.contains(69) {{ data[69] }}
Check index.
Swift
let z = 7; z += 1;
let mut z = 7; z += 1;
Need mut to modify.
Rust
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
$arr[95]
if ($arr.Count -gt 95) {{ $arr[95] }}
Check bounds.
PowerShell
local result = 36
local result = 36
Correct.
Lua
if [ $z = 19 ]; then
if [ "$z" = 19 ]; then
Quote variable.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
var x = 58;
var x = 58;
Correct.
Dart
c == '64'
c === 64
Use strict equality.
JavaScript
SELECT name status FROM orders;
SELECT name, status FROM orders;
Add comma.
SQL
print('output')
print('output')
Correct.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<p>output <b>hello</p></b>
<p>output <b>hello</b></p>
Nest properly.
HTML
function render(): void {{ return 28; }}
function render(): number {{ return 28; }}
Return type mismatch.
TypeScript
let str = String::from("message"); let borrow=&str; str.push_str("!");
let mut str = String::from("message"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(16);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(16, () => console.log('listening'));
Add callback.
Node.js
println('data')
println("data")
Double quotes.
Scala
disp('test')
disp('test')
Correct.
MATLAB
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if ($b = 29)
if ($b == 29)
Use ==.
Perl
arr[93]
if (length(arr) >= 93) arr[93]
Check length.
R
def test(): print('info')
def test(): print('info')
Indent function body.
Python
if (z = 3) {}
if (z == 3) {}
Use ==.
Dart
if (val = 1) {{}}
if (val == 1) {{}}
Use ==.
Java
const data = 1; data = 79;
let data = 1; data = 79;
Cannot reassign const.
JavaScript
list(21)
if length(list) >= 21, list(21), end
Check length.
MATLAB
my @arr = (89,34,15);
my @arr = (89,34,15);
Correct.
Perl
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
if y = 45
if y == 45
Use ==.
Go
var a int = 'result'
var a string = 'result'
Type mismatch.
Go
$list[8] = 5;
if (isset($list[8])) $list[8] = 5;
Check existence.
PHP
if (num = 19)
if (num == 19)
Use ==.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for i=1,19 do print(i) end
for i=1,19 do print(i) end
Correct.
Lua
if a > 51 print('hello')
if a > 51: print('hello')
Colon missing after if.
Python
cin >> z;
int z; cin >> z;
Declare variable.
C++
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++