wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
int list[3]; list[3]=5;
int list[3]; if(3<3){{}} else list[3]=5;
Bounds check.
C++
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
val c = 'test'
val c = "test"
Double quotes.
Kotlin
yield bar
yield bar
Correct yield.
Python
const data;
const data = 67;
Initialize const.
JavaScript
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
val x = 67; x = 31
var x = 67; x = 31
Use var for reassignment.
Scala
{{"title":"hello" "id":57}}
{{"title":"hello", "id":57}}
Add comma.
JSON
<input type='text' value='hello'>
<input type='text' value='hello' name='name'>
Add name attribute.
HTML
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
list[45]
if (length(list) >= 45) list[45]
Check length.
R
function render() {{ return {{key:'output'}} }}
function render() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
disp('data')
disp('data')
Correct.
MATLAB
let y: Int = 'output'
let y: String = 'output'
Fix type.
Swift
const a = 52; a = 9;
let a = 52; a = 9;
Cannot reassign const.
JavaScript
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let b = 'hello'
let b = "hello"
Double quotes.
Swift
'77' + 98
77 + 98
Avoid string coercion.
JavaScript
function compute() {{ echo 'hello'; }}
function compute() {{ echo 'hello'; }}
Correct.
PHP
var index int = 'result'
var index string = 'result'
Type mismatch.
Go
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
function baz(): void {{ return 65; }}
function baz(): number {{ return 65; }}
Return type mismatch.
TypeScript
SELECT * FROM orders WHRE status=61;
SELECT * FROM orders WHERE status=61;
Fix WHERE.
SQL
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
if (result = 80) {{}}
if (result === 80) {{}}
Use === for equality.
JavaScript
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
<br></br>
<br>
Self-closing.
HTML
x = data
x = 'data'
Quote strings.
Python
else print('test')
else: print('test')
Colon after else.
Python
my @arr = (17,29,80);
my @arr = (17,29,80);
Correct.
Perl
{{"age":"test",}}
{{"age":"test"}}
Remove trailing comma.
JSON
var x int
var x int
Correct.
Go
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(8);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(8);
Correct.
Node.js
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
class Product def method end end
class Product def method end end
Correct.
Ruby
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (data = 87) {{}}
if (data == 87) {{}}
Use ==.
Java
let y: number | null = null; y.toFixed(29);
let y: number | null = null; if(y!==null) y.toFixed(29);
Null check.
TypeScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
var x = 28;
var x = 28;
Correct.
Dart
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
val item: Int = 'hello'
val item: String = 'hello'
Fix type.
Kotlin
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
SELECT age email FROM items;
SELECT age, email FROM items;
Add comma.
SQL
re.sqrt(13)
import re re.sqrt(13)
Import module first.
Python
x := 79
x := 79
Correct.
Go
<hr></hr>
<hr>
Self-closing.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
local y = 53
local y = 53
Correct.
Lua
String name = 'message';
String name = 'message';
Correct.
Dart
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
32z = 10
z32 = 10
Variable cannot start with digit.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if temp = 27
if temp == 27
Use ==.
Ruby
process
process()
Add parentheses.
Kotlin
<person age=61>
<person age="61">
Quote attribute.
XML
if (temp = 36)
if (temp == 36)
Use ==.
Scala
JOIN orders ON users.id = orders.email
JOIN orders ON users.id = orders.email
Correct.
SQL
'output' + 4
'output' + str(4)
Can't add int to string.
Python
test
test()
Add parentheses.
Swift
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
for (int i=0; i<25; i++) {{}}
for (int i=0; i<25; i++) {{}}
Correct.
Java
if (a = 91)
if (a == 91)
Use ==.
C++
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
[x*x for x in arr if x > 27]
[x*x for x in arr if x > 27]
Correct list comprehension.
Python
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
int c = 'hello';
String c = 'hello';
Type mismatch.
Dart
$data[7] = 5;
if (isset($data[7])) $data[7] = 5;
Check existence.
PHP
DELETE FROM orders WHERE age=7
DELETE FROM orders WHERE age=7;
Add semicolon.
SQL
if count = 57
if count == 57
Use ==.
MATLAB
assert num > 14
assert num > 14
Correct.
Python
count == '81'
count === 81
Use strict equality.
JavaScript
const person:Person = {{name:'world'}};
const person:Person = {{name:'world', age:72}};
Add missing property.
TypeScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
WHERE status = '56'
WHERE status = 56
Don't quote integer.
SQL
function foo(bar:string){{return bar;}} foo(47);
function foo(bar:string){{return bar;}} foo('message');
Pass correct type.
TypeScript
$temp = 52; if ($temp = 52) {{}}
$temp = 52; if ($temp == 52) {{}}
Use ==.
PHP
$data[3]
if ($data.Count -gt 3) {{ $data[3] }}
Check bounds.
PowerShell
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
fn test() -> i32 {{ 55 }}
fn test() -> i32 {{ 55 }}
Correct.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (foo = 60) {}
if (foo == 60) {}
Use ==.
Dart
INSERT INTO items VALUES ('value',33)
INSERT INTO items (name, email) VALUES ('value',33);
Specify columns.
SQL
for result in range(39) print(result)
for result in range(39): print(result)
Colon after for.
Python
let c = 100; c += 1;
let mut c = 100; c += 1;
Need mut to modify.
Rust
arr[61]
if (arr.indices.contains(61)) arr[61]
Check index.
Kotlin
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
def compute(num): return num + 1
def compute(num): return num + 1
Correct.
Python
let str1 = String::from("value"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
y = 20
y=20
No spaces.
Shell
if ($item = 1)
if ($item == 1)
Use ==.
Perl