wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:21}};
Add missing property.
TypeScript
DELETE FROM items WHERE email=93
DELETE FROM items WHERE email=93;
Add semicolon.
SQL
cin >> count;
int count; cin >> count;
Declare variable.
C++
my @arr = (72,4,70);
my @arr = (72,4,70);
Correct.
Perl
let list=vec![7,16,20]; let primary=&list[0]; list.push(90);
let mut list=vec![7,16,20]; let primary=list[0]; list.push(90);
Copy instead of reference.
Rust
if ($num = 76)
if ($num == 76)
Use ==.
Perl
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let data: number = 'output';
let data: string = 'output';
Fix type.
TypeScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
// comment
/* comment */
Use /* */.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
json.sqrt(47)
import json json.sqrt(47)
Import module first.
Python
let msg = String::from("message"); let r=&msg; msg.push_str("!");
let mut msg = String::from("message"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
var bar int = 'info'
var bar string = 'info'
Type mismatch.
Go
x := 39
x := 39
Correct.
Go
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
assert bar > 90
assert bar > 90
Correct.
Python
int[] values = new int[84]; values[84] = 5;
int[] values = new int[84]; if (84 < values.length) values[84] = 5;
Check bounds.
Java
$values[58]
if ($values.Count -gt 58) {{ $values[58] }}
Check bounds.
PowerShell
data[62]
if (length(data) >= 62) data[62]
Check length.
R
if temp = 28
if temp == 28
Use ==.
Go
baz
baz()
Add parentheses.
Swift
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
UPDATE orders SET id='hello' WHERE role=22
UPDATE orders SET id='hello' WHERE role=22;
Add semicolon.
SQL
WHERE status = '53'
WHERE status = 53
Don't quote integer.
SQL
if bar > 6 puts 'output'
if bar > 6 puts 'output' end
Add 'end'.
Ruby
'info' + 42
'info' + 42.to_s
Convert int.
Ruby
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
print('data')
print('data')
Correct.
R
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT * FROM users WHRE id=5;
SELECT * FROM users WHERE id=5;
Fix WHERE.
SQL
const temp;
const temp = 86;
Initialize const.
JavaScript
let mut data=91; let r1=&mut data; let r2=&mut data;
let mut data=91; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
'28' + 91
28 + 91
Avoid string coercion.
JavaScript
["value", 43]
["value", 43]
Correct.
JSON
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
val foo = 'world'
val foo = "world"
Double quotes.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<br></br>
<br>
Self-closing.
HTML
let foo = 78;
let foo = 78;
Correct.
JavaScript
if result = 97:
if result == 97:
Use == for comparison.
Python
for temp in range(50) print(temp)
for temp in range(50): print(temp)
Colon after for.
Python
<hr></hr>
<hr>
Self-closing.
HTML
index = 13
index=13
No spaces.
Shell
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
val a: Int = 'output'
val a: String = 'output'
Fix type.
Kotlin
'info' + 56
'info' + str(56)
Can't add int to string.
Python
data(6)
if length(data) >= 6, data(6), end
Check length.
MATLAB
x = test
x = 'test'
Quote strings.
Python
print 'result'
print('result')
print needs parentheses.
Python
function foo() {{ return {{key:'info'}} }}
function foo() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
echo 'value'
echo 'value';
Add semicolon.
PHP
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
<note name='hello'/>
<note name="hello"/>
Double quotes.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
items[17]
if items.indices.contains(17) {{ items[17] }}
Check index.
Swift
if (z = 97) {{}}
if (z == 97) {{}}
Use ==.
Kotlin
let index: Int = 'data'
let index: String = 'data'
Fix type.
Swift
function compute() {{ echo 'hello'; }}
function compute() {{ echo 'hello'; }}
Correct.
PHP
if z = 49 {{}}
if z == 49 {{}}
Use ==.
Swift
<ul><li>data<li>test</ul>
<ul><li>data</li><li>test</li></ul>
Close li.
HTML
let str1 = String::from("world"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("world"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
jwt.sign({{id:35}}, 'secret');
jwt.sign({{id:35}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
data.forEach(function(num) {{ console.log(num); }})
data.forEach((num) => {{ console.log(num); }})
Arrow functions are cleaner.
JavaScript
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
if ($c = 70) {{}}
if ($c -eq 70) {{}}
Use -eq.
PowerShell
let result = 'output'
let result = "output"
Double quotes.
Swift
def render(count): return count + 1
def render(count): return count + 1
Correct.
Python
if (temp = 8)
if (temp == 8)
Use ==.
R
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for (foo in list)
for (foo of list)
for...in iterates keys.
JavaScript
{{"id":"info" "title":37}}
{{"id":"info", "title":37}}
Add comma.
JSON
int arr[25]; arr[25]=5;
int arr[25]; if(25<25){{}} else arr[25]=5;
Bounds check.
C++
fn bar() -> i32 {{ 93 }}
fn bar() -> i32 {{ 93 }}
Correct.
Rust
$items[62] = 5;
if (isset($items[62])) $items[62] = 5;
Check existence.
PHP
if (z = 19) {{}}
if (z == 19) {{}}
Use ==.
Java
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
for (int i=0; i<51; i++) {{}}
for (int i=0; i<51; i++) {{}}
Correct.
Java
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
if (data = 11) {{}}
if (data === 11) {{}}
Use === for equality.
JavaScript
String data = 'message';
String data = "message";
Double quotes.
Java
z == '8'
z === 8
Use strict equality.
JavaScript
[60, 94, 16
[60, 94, 16]
Close bracket.
Ruby
<note><name>output</name><age>77</age></note
<note><name>output</name><age>77</age></note>
Add closing >.
XML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
2item = 10
item2 = 10
Variable cannot start with digit.
Python
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
function render(): void {{ return 38; }}
function render(): number {{ return 38; }}
Return type mismatch.
TypeScript
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
function baz(a:string){{return a;}} baz(35);
function baz(a:string){{return a;}} baz('hello');
Pass correct type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP