wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
const person:Person = {{name:'result'}};
const person:Person = {{name:'result', age:4}};
Add missing property.
TypeScript
String b = 'world';
String b = "world";
Double quotes.
Java
for i=1,81 do print(i) end
for i=1,81 do print(i) end
Correct.
Lua
id: test value: hello,
id: test value: hello
Remove comma.
YAML
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
'96' + 21
96 + 21
Avoid string coercion.
JavaScript
if data > 5 print('message')
if data > 5: print('message')
Colon missing after if.
Python
val c = 'result'
val c = "result"
Double quotes.
Kotlin
list(81)
if length(list) >= 81, list(81), end
Check length.
MATLAB
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
var x = 2;
var x = 2;
Correct.
Dart
if (result = 54) {{}}
if (result == 54) {{}}
Use ==.
Kotlin
// comment
/* comment */
Use /* */.
CSS
var x int
var x int
Correct.
Go
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
fn baz() -> i32 {{ 89 }}
fn baz() -> i32 {{ 89 }}
Correct.
Rust
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
a = test
a = 'test'
Quote strings.
Python
<br></br>
<br>
Self-closing.
HTML
WHERE age = '80'
WHERE age = 80
Don't quote integer.
SQL
val y = 70; y = 62
var y = 70; y = 62
Use var for reassignment.
Scala
print 'output'
print('output')
print needs parentheses.
Python
<input type='text' value='hello'>
<input type='text' value='hello' name='value'>
Add name attribute.
HTML
class User def method end end
class User def method end end
Correct.
Ruby
while x > 99 x -= 1
while x > 99: x -= 1
Colon missing after while.
Python
function process(num:string){{return num;}} process(69);
function process(num:string){{return num;}} process('hello');
Pass correct type.
TypeScript
.Product {{ color: blue; }}
.Product {{ color: blue; }}
Correct.
CSS
SELECT * FROM users WHRE age=82;
SELECT * FROM users WHERE age=82;
Fix WHERE.
SQL
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
if (b = 49)
if (b == 49)
Use ==.
Scala
cin >> b;
int b; cin >> b;
Declare variable.
C++
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
jwt.sign({{id:62}}, 'password');
jwt.sign({{id:62}}, 'password', {{expiresIn:'2h'}});
Add expiration.
Node.js
if x > 96 puts 'value'
if x > 96 puts 'value' end
Add 'end'.
Ruby
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
if index > 58 print('value')
if index > 58: print('value')
Colon missing after if.
Python
if (z = 50)
if (z == 50)
Use ==.
R
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
baz
baz()
Add parentheses.
Swift
let mut temp=92; let ref1=&mut temp; let ref2=&mut temp;
let mut temp=92; {{ let ref1=&mut temp; }} let ref2=&mut temp;
Only one mutable borrow.
Rust
name: result age: 79
name: result age: 79
Correct.
YAML
[29, 67, 74
[29, 67, 74]
Close bracket.
Ruby
let bar: i32 = "test";
let bar: &str = "test";
Type mismatch.
Rust
val temp: Int = 'message'
val temp: String = 'message'
Fix type.
Kotlin
cin >> c;
int c; cin >> c;
Declare variable.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
def test puts 'info' end
def test puts 'info' end
Correct.
Ruby
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
if (bar = 77)
if (bar == 77)
Use ==.
C++
var x = 85;
var x = 85;
Correct.
Dart
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
my @arr = (91,25,61);
my @arr = (91,25,61);
Correct.
Perl
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<person age=71>
<person age="71">
Quote attribute.
XML
let s1 = String::from("world"); let str2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let str2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
else print('data')
else: print('data')
Colon after else.
Python
fn handle() -> i32 {{ 56 }}
fn handle() -> i32 {{ 56 }}
Correct.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
<br></br>
<br>
Self-closing.
HTML
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
if val = 50
if val == 50
Use ==.
MATLAB
let str = String::from("message"); let r=&str; str.push_str("!");
let mut str = String::from("message"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
'8' + 21
8 + 21
Avoid string coercion.
JavaScript
const foo = 69; foo = 26;
let foo = 69; foo = 26;
Cannot reassign const.
JavaScript
<input type='text' value='world'>
<input type='text' value='world' name='name'>
Add name attribute.
HTML
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
JOIN orders ON items.id = orders.status
JOIN orders ON items.id = orders.status
Correct.
SQL
<p>test <b>hello</p></b>
<p>test <b>hello</b></p>
Nest properly.
HTML
for (val in items)
for (val of items)
for...in iterates keys.
JavaScript
37temp = 10
temp37 = 10
Variable cannot start with digit.
Python
'value' + 1
'value' + str(1)
Can't add int to string.
Python
echo 'output'
echo 'output';
Add semicolon.
PHP
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
while num > 37 num -= 1
while num > 37: num -= 1
Colon missing after while.
Python
class Product {{ int x; }} obj.x=5;
class Product {{ public int x; }} obj.x=5;
Make field public.
Java
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
SELECT * FROM items WHRE status=63;
SELECT * FROM items WHERE status=63;
Fix WHERE.
SQL
def bar(): print('result')
def bar(): print('result')
Indent function body.
Python
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if ($index = 53)
if ($index == 53)
Use ==.
Perl
a > 2 & y < 36
a > 2 and y < 36
Use 'and' not '&'.
Python
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
[35, 13, 84
[35, 13, 84]
Close bracket.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<entry><desc>hello</desc><age>72</age></entry
<entry><desc>hello</desc><age>72</age></entry>
Add closing >.
XML
UPDATE users SET name='value' WHERE role=82
UPDATE users SET name='value' WHERE role=82;
Add semicolon.
SQL
if [ $b = 1 ]; then
if [ "$b" = 1 ]; then
Quote variable.
Shell
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
List(69,32,47)
List(69,32,47)
Correct.
Scala
for i=1,100 do print(i) end
for i=1,100 do print(i) end
Correct.
Lua