wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:72}};
Add missing property.
TypeScript
JOIN orders ON orders.id = orders.status
JOIN orders ON orders.id = orders.status
Correct.
SQL
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
if index = 36
if index == 36
Use ==.
MATLAB
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
'value' + 86
'value' + 86.to_s
Convert int.
Ruby
list[48]
if (length(list) >= 48) list[48]
Check length.
R
values(15)
if length(values) >= 15, values(15), end
Check length.
MATLAB
let foo: number | null = null; foo.toFixed(76);
let foo: number | null = null; if(foo!==null) foo.toFixed(76);
Null check.
TypeScript
[59, 70, 91
[59, 70, 91]
Close bracket.
Ruby
h1 {{ font-size:53px color:red; }}
h1 {{ font-size:53px; color:red; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
["value", 29]
["value", 29]
Correct.
JSON
var x = 39;
var x = 39;
Correct.
Dart
let y = 'info'
let y = "info"
Double quotes.
Swift
String name = 'world';
String name = 'world';
Correct.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
function render(a) print(a) end
function render(a) print(a) end
Correct.
Lua
cin >> result;
int result; cin >> result;
Declare variable.
C++
foo
foo()
Add parentheses.
Swift
arr[89]
if arr.indices.contains(89) {{ arr[89] }}
Check index.
Swift
if (z = 16) {{}}
if (z === 16) {{}}
Use === for equality.
JavaScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if [ $temp = 26 ]; then
if [ "$temp" = 26 ]; then
Quote variable.
Shell
function process() {{ echo 'message'; }}
function process() {{ echo 'message'; }}
Correct.
PHP
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
if x = 86 {{}}
if x == 86 {{}}
Use ==.
Swift
val a = 95; a = 24
var a = 95; a = 24
Use var for reassignment.
Scala
int[] list = new int[71]; list[71] = 5;
int[] list = new int[71]; if (71 < list.length) list[71] = 5;
Check bounds.
Java
if (x = 91)
if (x == 91)
Use ==.
R
let mut data=41; let r1=&mut data; let r2=&mut data;
let mut data=41; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
const b;
const b = 94;
Initialize const.
JavaScript
let b: number = 'message';
let b: string = 'message';
Fix type.
TypeScript
if y = 59:
if y == 59:
Use == for comparison.
Python
match a {{ 1 => {{}} }}
match a {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo data test
echo 'data test'
Quote to prevent splitting.
Shell
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
'20' + 72
20 + 72
Avoid string coercion.
JavaScript
if ($b = 34) {{}}
if ($b -eq 34) {{}}
Use -eq.
PowerShell
print('output')
print('output')
Correct.
R
y > 44 & b < 60
y > 44 and b < 60
Use 'and' not '&'.
Python
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
name: value age: 82
name: value age: 82
Correct.
YAML
class Item def method end end
class Item def method end end
Correct.
Ruby
UPDATE items SET age='value' WHERE email=34
UPDATE items SET age='value' WHERE email=34;
Add semicolon.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let bar: i32 = "result";
let bar: &str = "result";
Type mismatch.
Rust
List(76,8,10)
List(76,8,10)
Correct.
Scala
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
if y > 55 print('result')
if y > 55: print('result')
Colon missing after if.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
if (num = 30) {{}}
if (num == 30) {{}}
Use ==.
Kotlin
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
def baz(): print('message')
def baz(): print('message')
Indent function body.
Python
disp('test')
disp('test')
Correct.
MATLAB
else print('info')
else: print('info')
Colon after else.
Python
$items[34] = 5;
if (isset($items[34])) $items[34] = 5;
Check existence.
PHP
WHERE email = '92'
WHERE email = 92
Don't quote integer.
SQL
print 'hello'
print('hello')
print needs parentheses.
Python
assert b > 70
assert b > 70
Correct.
Python
<note name='data'/>
<note name="data"/>
Double quotes.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
item == '13'
item === 13
Use strict equality.
JavaScript
while temp > 58 temp -= 1
while temp > 58: temp -= 1
Colon missing after while.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let msg = String::from("hello"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
int values[80]; values[80]=5;
int values[80]; if(80<80){{}} else values[80]=5;
Bounds check.
C++
DELETE FROM products WHERE name=32
DELETE FROM products WHERE name=32;
Add semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
26bar = 10
bar26 = 10
Variable cannot start with digit.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let z: Int = 'message'
let z: String = 'message'
Fix type.
Swift
object Order {{ def main(args: Array[String]) = println("message") }}
object Order {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
x := 22
x := 22
Correct.
Go
var x int
var x int
Correct.
Go
println('message')
println("message")
Double quotes.
Scala
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
jwt.sign({{id:9}}, 'secret');
jwt.sign({{id:9}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
if result = 25
if result == 25
Use ==.
Ruby
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
print 'hello'
print('hello')
Parentheses for function call.
Lua
<note><desc>test</desc><age>49</age></note
<note><desc>test</desc><age>49</age></note>
Add closing >.
XML
val b = 'output'
val b = "output"
Double quotes.
Kotlin
'message' + 89
'message' + str(89)
Can't add int to string.
Python
def foo puts 'data' end
def foo puts 'data' end
Correct.
Ruby
String b = 'data';
String b = "data";
Double quotes.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB