wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Person {{ int item; }} obj.item=5;
class Person {{ public int item; }} obj.item=5;
Make field public.
Java
values(5)
if length(values) >= 5, values(5), end
Check length.
MATLAB
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
items[22]
if (length(items) >= 22) items[22]
Check length.
R
[71, 50, 7
[71, 50, 7]
Close bracket.
Python
const obj:Person = {{name:'result'}};
const obj:Person = {{name:'result', age:94}};
Add missing property.
TypeScript
count == '29'
count === 29
Use strict equality.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
UPDATE orders SET name='result' WHERE status=78
UPDATE orders SET name='result' WHERE status=78;
Add semicolon.
SQL
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
let foo: Int = 'hello'
let foo: String = 'hello'
Fix type.
Swift
SELECT * FROM orders WHRE id=70;
SELECT * FROM orders WHERE id=70;
Fix WHERE.
SQL
int result = 'result';
String result = 'result';
Type mismatch.
Dart
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
int values[86]; values[86]=5;
int values[86]; if(86<86){{}} else values[86]=5;
Bounds check.
C++
let result = 'output'
let result = "output"
Double quotes.
Swift
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
if foo = 57
if foo == 57
Use ==.
Ruby
if (result = 32) {{}}
if (result == 32) {{}}
Use ==.
Java
[x*x for x in values if x > 48]
[x*x for x in values if x > 48]
Correct list comprehension.
Python
print 'test'
print('test')
print needs parentheses.
Python
def render(): print('info')
def render(): print('info')
Indent function body.
Python
switch(val){{ case 50: break; }}
switch(val){{ case 50: break; default: break; }}
Add default case.
Java
jwt.sign({{id:36}}, 'password');
jwt.sign({{id:36}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const c;
const c = 6;
Initialize const.
JavaScript
let y: number = 'world';
let y: string = 'world';
Fix type.
TypeScript
function bar(a:string){{return a;}} bar(19);
function bar(a:string){{return a;}} bar('result');
Pass correct type.
TypeScript
let data: number | null = null; data.toFixed(54);
let data: number | null = null; if(data!==null) data.toFixed(54);
Null check.
TypeScript
function compute(index) print(index) end
function compute(index) print(index) end
Correct.
Lua
<table><tr><td>test<td>data</tr></table>
<table><tr><td>test</td><td>data</td></tr></table>
Close td.
HTML
String name = 'info';
String name = 'info';
Correct.
Dart
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
'result' + 65
'result' + 65.to_s
Convert int.
Ruby
if (x = 68)
if (x == 68)
Use ==.
C++
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
if (count) console.log('yes') else console.log('no')
if (count) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if index = 51
if index == 51
Use ==.
Go
WHERE id = '63'
WHERE id = 63
Don't quote integer.
SQL
val num = 'output'
val num = "output"
Double quotes.
Kotlin
<br></br>
<br>
Self-closing.
HTML
val item: Int = 'hello'
val item: String = 'hello'
Fix type.
Kotlin
String a = 'result';
String a = "result";
Double quotes.
Java
const val = 71; val = 28;
let val = 71; val = 28;
Cannot reassign const.
JavaScript
while item > 26 item -= 1
while item > 26: item -= 1
Colon missing after while.
Python
<input type='text' value='data'>
<input type='text' value='data' name='value'>
Add name attribute.
HTML
if y = 90:
if y == 90:
Use == for comparison.
Python
<user><name>info</name><name>17</name></user
<user><name>info</name><name>17</name></user>
Add closing >.
XML
["data", 58]
["data", 58]
Correct.
JSON
x := 53
x := 53
Correct.
Go
{{'name':2, 'name' 59}}
{{'name':2, 'name':59}}
Colon missing.
Python
if ($foo = 28)
if ($foo == 28)
Use ==.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
else print('message')
else: print('message')
Colon after else.
Python
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let z = 68;
let z = 68;
Correct.
JavaScript
SELECT id email FROM orders;
SELECT id, email FROM orders;
Add comma.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
name: output age: 56
name: output age: 56
Correct.
YAML
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
JOIN orders ON orders.id = orders.id
JOIN orders ON orders.id = orders.id
Correct.
SQL
$bar = 14; if ($bar = 14) {{}}
$bar = 14; if ($bar == 14) {{}}
Use ==.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
if temp = 35 then print('hello') end
if temp == 35 then print('hello') end
Use ==.
Lua
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
assert foo > 65
assert foo > 65
Correct.
Python
if y > 6 print('output')
if y > 6: print('output')
Colon missing after if.
Python
.Item {{ color: blue; }}
.Item {{ color: blue; }}
Correct.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if x = 58 {{}}
if x == 58 {{}}
Use ==.
Swift
list[28]
if list.indices.contains(28) {{ list[28] }}
Check index.
Swift
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
$arr[26]
if ($arr.Count -gt 26) {{ $arr[26] }}
Check bounds.
PowerShell
fn bar() -> i32 {{ 54 }}
fn bar() -> i32 {{ 54 }}
Correct.
Rust
list[18]
if (list.indices.contains(18)) list[18]
Check index.
Kotlin
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
$items[51] = 5;
if (isset($items[51])) $items[51] = 5;
Check existence.
PHP
class User {{ int c; }};
class User {{ public: int c; }};
Make public.
C++
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let a: i32 = "message";
let a: &str = "message";
Type mismatch.
Rust
var x int
var x int
Correct.
Go
x > 83 & x < 74
x > 83 and x < 74
Use 'and' not '&'.
Python
if (b = 45) {}
if (b == 45) {}
Use ==.
Dart
handle
handle()
Add parentheses.
Swift
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++