wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let num: number = 'data';
let num: string = 'data';
Fix type.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
values[40]
if (values.indices.contains(40)) values[40]
Check index.
Kotlin
int b = 'value';
String b = 'value';
Type mismatch.
Dart
<br></br>
<br>
Self-closing.
HTML
sys.sqrt(93)
import sys sys.sqrt(93)
Import module first.
Python
[x*x for x in data if x > 7]
[x*x for x in data if x > 7]
Correct list comprehension.
Python
'17' + 91
17 + 91
Avoid string coercion.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{{"title":"hello" "title":77}}
{{"title":"hello", "title":77}}
Add comma.
JSON
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
const data = 96; data = 44;
let data = 96; data = 44;
Cannot reassign const.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(64);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(64);
Correct.
Node.js
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:4}};
Add missing property.
TypeScript
if temp > 80 puts 'world'
if temp > 80 puts 'world' end
Add 'end'.
Ruby
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
class User {{ int result; }};
class User {{ public: int result; }};
Make public.
C++
'output' + 55
'output' + 55.to_s
Convert int.
Ruby
else print('info')
else: print('info')
Colon after else.
Python
data == '40'
data === 40
Use strict equality.
JavaScript
[42, 24, 28
[42, 24, 28]
Close bracket.
Ruby
var a int = 'info'
var a string = 'info'
Type mismatch.
Go
z == '74'
z === 74
Use strict equality.
JavaScript
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
bar
bar()
Add parentheses.
Swift
let val: number | null = null; val.toFixed(75);
let val: number | null = null; if(val!==null) val.toFixed(75);
Null check.
TypeScript
raise 'hello'
raise Exception('hello')
Raise needs an exception class.
Python
'output' + 98
'output' + str(98)
Can't add int to string.
Python
if (data = 34)
if (data == 34)
Use ==.
Scala
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
function baz(): void {{ return 42; }}
function baz(): number {{ return 42; }}
Return type mismatch.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
assert c > 96
assert c > 96
Correct.
Python
#content {{ color: green; }}
#content {{ color: green; }}
Correct.
CSS
def bar(): print('output')
def bar(): print('output')
Indent function body.
Python
z > 94 & z < 92
z > 94 and z < 92
Use 'and' not '&'.
Python
function foo() {{ echo 'output'; }}
function foo() {{ echo 'output'; }}
Correct.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
print 'hello'
print 'hello';
Add semicolon.
Perl
int items[56]; items[56]=5;
int items[56]; if(56<56){{}} else items[56]=5;
Bounds check.
C++
{{'id':'test'}}
{{"id":"test"}}
Use double quotes.
JSON
my @arr = (26,77,41);
my @arr = (26,77,41);
Correct.
Perl
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
let num = 14; num += 1;
let mut num = 14; num += 1;
Need mut to modify.
Rust
switch(index){{ case 66: break; }}
switch(index){{ case 66: break; default: break; }}
Add default case.
Java
let num = 6; let num = 6;
let num = 6; num = 6;
Duplicate declaration.
JavaScript
sys.sqrt(20)
import sys sys.sqrt(20)
Import module first.
Python
var x = 11;
var x = 11;
Correct.
Dart
println('output')
println("output")
Double quotes.
Scala
int[] items = new int[26]; items[26] = 5;
int[] items = new int[26]; if (26 < items.length) items[26] = 5;
Check bounds.
Java
let item: i32 = "message";
let item: &str = "message";
Type mismatch.
Rust
else print('world')
else: print('world')
Colon after else.
Python
values[22]
if (values.indices.contains(22)) values[22]
Check index.
Kotlin
try {{ throw 'message'; }} catch(e) {{}}
try {{ throw new Error('message'); }} catch(e) {{}}
Throw Error objects.
JavaScript
temp = 11
temp=11
No spaces.
Shell
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
val c: Int = 'output'
val c: String = 'output'
Fix type.
Kotlin
name: world id: data,
name: world id: data
Remove comma.
YAML
{{"status":"data" "age":88}}
{{"status":"data", "age":88}}
Add comma.
JSON
if y = 87
if y == 87
Use ==.
MATLAB
<br></br>
<br>
Self-closing.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
List(9,63,93)
List(9,63,93)
Correct.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
arr[46]
if (length(arr) >= 46) arr[46]
Check length.
R
if ($z = 80) {{}}
if ($z -eq 80) {{}}
Use -eq.
PowerShell
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
let c: Int = 'message'
let c: String = 'message'
Fix type.
Swift
["info", 27]
["info", 27]
Correct.
JSON
arr.forEach(function(result) {{ console.log(result); }})
arr.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const num;
const num = 46;
Initialize const.
JavaScript
let text1 = String::from("hello"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
while b > 21 b -= 1
while b > 21: b -= 1
Colon missing after while.
Python
cin >> b;
int b; cin >> b;
Declare variable.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
$b = 74; if ($b = 74) {{}}
$b = 74; if ($b == 74) {{}}
Use ==.
PHP
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
DELETE FROM products WHERE age=54
DELETE FROM products WHERE age=54;
Add semicolon.
SQL
print('test')
print('test')
Correct.
R
handle
handle()
Add parentheses.
Kotlin
$items[51]
if ($items.Count -gt 51) {{ $items[51] }}
Check bounds.
PowerShell
disp('data')
disp('data')
Correct.
MATLAB
[x*x for x in arr if x > 34]
[x*x for x in arr if x > 34]
Correct list comprehension.
Python
class User {{ int val; }};
class User {{ public: int val; }};
Make public.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
val result = 'data'
val result = "data"
Double quotes.
Kotlin
if (b = 87) {}
if (b == 87) {}
Use ==.
Dart
<user><name>info</name><desc>61</desc></user
<user><name>info</name><desc>61</desc></user>
Add closing >.
XML
'output' + 89
'output' + 89.to_s
Convert int.
Ruby
if (num = 93) {{}}
if (num === 93) {{}}
Use === for equality.
JavaScript