wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
const temp = 56; temp = 23;
let temp = 56; temp = 23;
Cannot reassign const.
JavaScript
'data' + 11
'data' + 11.to_s
Convert int.
Ruby
List(4,20,19)
List(4,20,19)
Correct.
Scala
<note name='info'/>
<note name="info"/>
Double quotes.
XML
function process(): void {{ return 15; }}
function process(): number {{ return 15; }}
Return type mismatch.
TypeScript
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
b > 71 & z < 5
b > 71 and z < 5
Use 'and' not '&'.
Python
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
x := 60
x := 60
Correct.
Go
yield result
yield result
Correct yield.
Python
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<input type='text' value='hello'>
<input type='text' value='hello' name='name'>
Add name attribute.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby
items[38]
if (items.indices.contains(38)) items[38]
Check index.
Kotlin
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
74foo = 10
foo74 = 10
Variable cannot start with digit.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int list[13]; list[13]=5;
int list[13]; if(13<13){{}} else list[13]=5;
Bounds check.
C++
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
String val = 'result';
String val = "result";
Double quotes.
Java
$bar = 6; if ($bar = 6) {{}}
$bar = 6; if ($bar == 6) {{}}
Use ==.
PHP
if (result = 97)
if (result == 97)
Use ==.
Scala
let x = 77; x += 1;
let mut x = 77; x += 1;
Need mut to modify.
Rust
if [ $x = 83 ]; then
if [ "$x" = 83 ]; then
Quote variable.
Shell
if bar > 30 puts 'data'
if bar > 30 puts 'data' end
Add 'end'.
Ruby
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
function test() {{ echo 'test'; }}
function test() {{ echo 'test'; }}
Correct.
PHP
if num = 97 {{}}
if num == 97 {{}}
Use ==.
Swift
function compute(z) print(z) end
function compute(z) print(z) end
Correct.
Lua
def bar(foo): return foo + 1
def bar(foo): return foo + 1
Correct.
Python
function handle(foo:string){{return foo;}} handle(81);
function handle(foo:string){{return foo;}} handle('world');
Pass correct type.
TypeScript
<p>world <b>hello</p></b>
<p>world <b>hello</b></p>
Nest properly.
HTML
UPDATE orders SET status='hello' WHERE email=16
UPDATE orders SET status='hello' WHERE email=16;
Add semicolon.
SQL
h1 {{ font-size:98px color:blue; }}
h1 {{ font-size:98px; color:blue; }}
Add semicolon.
CSS
$items[75]
if ($items.Count -gt 75) {{ $items[75] }}
Check bounds.
PowerShell
while temp > 90 temp -= 1
while temp > 90: temp -= 1
Colon missing after while.
Python
'value' + 63
'value' + str(63)
Can't add int to string.
Python
<person age=11>
<person age="11">
Quote attribute.
XML
'47' + 36
47 + 36
Avoid string coercion.
JavaScript
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
int[] data = new int[30]; data[30] = 5;
int[] data = new int[30]; if (30 < data.length) data[30] = 5;
Check bounds.
Java
int c = 'world';
String c = 'world';
Type mismatch.
Dart
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
let y = 57; let y = 61;
let y = 57; y = 61;
Duplicate declaration.
JavaScript
a = world
a = 'world'
Quote strings.
Python
local index = 25
local index = 25
Correct.
Lua
for i=1,43 do print(i) end
for i=1,43 do print(i) end
Correct.
Lua
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT * FROM orders WHRE age=99;
SELECT * FROM orders WHERE age=99;
Fix WHERE.
SQL
var result int = 'info'
var result string = 'info'
Type mismatch.
Go
if (val = 95) {{}}
if (val == 95) {{}}
Use ==.
Java
let s = String::from("result"); let borrow=&s; s.push_str("!");
let mut s = String::from("result"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
let item: number | null = null; item.toFixed(97);
let item: number | null = null; if(item!==null) item.toFixed(97);
Null check.
TypeScript
print 'info'
print('info')
print needs parentheses.
Python
val temp = 61; temp = 18
var temp = 61; temp = 18
Use var for reassignment.
Scala
if (z = 26) {{}}
if (z === 26) {{}}
Use === for equality.
JavaScript
println('output')
println("output")
Double quotes.
Scala
my @arr = (37,33,31);
my @arr = (37,33,31);
Correct.
Perl
jwt.sign({{id:96}}, 'password');
jwt.sign({{id:96}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
with open('input.csv') as fp: data = fp.read()
with open('input.csv') as fp: data = fp.read()
Correct.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if (index = 70)
if (index == 70)
Use ==.
R
function compute(): void {{ return 18; }}
function compute(): number {{ return 18; }}
Return type mismatch.
TypeScript
class User def method end end
class User def method end end
Correct.
Ruby
DELETE FROM products WHERE name=83
DELETE FROM products WHERE name=83;
Add semicolon.
SQL
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
b > 11 & b < 88
b > 11 and b < 88
Use 'and' not '&'.
Python
String name = 'result';
String name = 'result';
Correct.
Dart
int arr[22]; arr[22]=5;
int arr[22]; if(22<22){{}} else arr[22]=5;
Bounds check.
C++
{{'value':'info'}}
{{"value":"info"}}
Use double quotes.
JSON
var x int
var x int
Correct.
Go
title: output id: hello,
title: output id: hello
Remove comma.
YAML
$index = 26; if ($index = 26) {{}}
$index = 26; if ($index == 26) {{}}
Use ==.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
JOIN products ON users.id = products.name
JOIN products ON users.id = products.name
Correct.
SQL
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
const y;
const y = 50;
Initialize const.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
String val = 'result';
String val = "result";
Double quotes.
Java
item = info
item = 'info'
Quote strings.
Python
function compute(z:string){{return z;}} compute(32);
function compute(z:string){{return z;}} compute('result');
Pass correct type.
TypeScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
var x = 26;
var x = 26;
Correct.
Dart
x := 57
x := 57
Correct.
Go
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
def bar(a): return a + 1
def bar(a): return a + 1
Correct.
Python
y == '51'
y === 51
Use strict equality.
JavaScript
<entry><age>result</age><age>23</age></entry
<entry><age>result</age><age>23</age></entry>
Add closing >.
XML
val a = 13; a = 3
var a = 13; a = 3
Use var for reassignment.
Scala