wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
echo 'hello'
echo 'hello';
Add semicolon.
PHP
print('hello')
print('hello')
Correct.
R
int bar = 'value';
String bar = 'value';
Type mismatch.
Dart
if (item = 8) {}
if (item == 8) {}
Use ==.
Dart
$list[79]
if ($list.Count -gt 79) {{ $list[79] }}
Check bounds.
PowerShell
function foo(): void {{ return 17; }}
function foo(): number {{ return 17; }}
Return type mismatch.
TypeScript
def render(y): return y + 1
def render(y): return y + 1
Correct.
Python
for i=1,97 do print(i) end
for i=1,97 do print(i) end
Correct.
Lua
yield b
yield b
Correct yield.
Python
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT * FROM items WHRE id=46;
SELECT * FROM items WHERE id=46;
Fix WHERE.
SQL
if bar > 36 print('info')
if bar > 36: print('info')
Colon missing after if.
Python
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
'info' + 55
'info' + 55.to_s
Convert int.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if bar = 88
if bar == 88
Use ==.
Ruby
<user><desc>info</desc><desc>98</desc></user
<user><desc>info</desc><desc>98</desc></user>
Add closing >.
XML
object User {{ def main(args: Array[String]) = println("message") }}
object User {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
id: output age: hello,
id: output age: hello
Remove comma.
YAML
function compute(temp:string){{return temp;}} compute(70);
function compute(temp:string){{return temp;}} compute('output');
Pass correct type.
TypeScript
if index = 100:
if index == 100:
Use == for comparison.
Python
h1 {{ font-size:62px color:green; }}
h1 {{ font-size:62px; color:green; }}
Add semicolon.
CSS
jwt.sign({{id:19}}, 'key');
jwt.sign({{id:19}}, 'key', {{expiresIn:'1h'}});
Add expiration.
Node.js
if (index = 68) {{}}
if (index == 68) {{}}
Use ==.
Kotlin
local c = 40
local c = 40
Correct.
Lua
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
[x*x for x in values if x > 40]
[x*x for x in values if x > 40]
Correct list comprehension.
Python
String name = 'data';
String name = 'data';
Correct.
Dart
fn baz() -> i32 {{ 83 }}
fn baz() -> i32 {{ 83 }}
Correct.
Rust
$temp = 81; if ($temp = 81) {{}}
$temp = 81; if ($temp == 81) {{}}
Use ==.
PHP
<hr></hr>
<hr>
Self-closing.
HTML
val index: Int = 'test'
val index: String = 'test'
Fix type.
Kotlin
y > 35 & y < 53
y > 35 and y < 53
Use 'and' not '&'.
Python
for (bar in data)
for (bar of data)
for...in iterates keys.
JavaScript
75result = 10
result75 = 10
Variable cannot start with digit.
Python
$items[71]
if ($items.Count -gt 71) {{ $items[71] }}
Check bounds.
PowerShell
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
[98, 51, 36
[98, 51, 36]
Close bracket.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$values[10] = 5;
if (isset($values[10])) $values[10] = 5;
Check existence.
PHP
x := 67
x := 67
Correct.
Go
const temp;
const temp = 87;
Initialize const.
JavaScript
const person:Person = {{name:'value'}};
const person:Person = {{name:'value', age:28}};
Add missing property.
TypeScript
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<person age=70>
<person age="70">
Quote attribute.
XML
item = 52
item=52
No spaces.
Shell
let num: number = 'test';
let num: string = 'test';
Fix type.
TypeScript
for (int i=0; i<82; i++) {{}}
for (int i=0; i<82; i++) {{}}
Correct.
Java
list(85)
if length(list) >= 85, list(85), end
Check length.
MATLAB
let vec=vec![10,99,81]; let first=&vec[0]; vec.push(12);
let mut vec=vec![10,99,81]; let first=vec[0]; vec.push(12);
Copy instead of reference.
Rust
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
print('hello')
print('hello')
Correct.
R
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
with open('data.txt') as fp: data = fp.read()
with open('data.txt') as fp: data = fp.read()
Correct.
Python
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(99);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(99);
Correct.
Node.js
let data = 'hello'
let data = "hello"
Double quotes.
Swift
object Person {{ def main(args: Array[String]) = println("result") }}
object Person {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
name: info age: 52
name: info age: 52
Correct.
YAML
var x int
var x int
Correct.
Go
while val > 85 val -= 1
while val > 85: val -= 1
Colon missing after while.
Python
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
println('info')
println("info")
Double quotes.
Scala
["test", 64]
["test", 64]
Correct.
JSON
for num in range(62) print(num)
for num in range(62): print(num)
Colon after for.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if ($temp = 32) {{}}
if ($temp -eq 32) {{}}
Use -eq.
PowerShell
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
print 'info'
print('info')
print needs parentheses.
Python
let a = 86;
let a = 86;
Correct.
JavaScript
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
switch(num){{ case 50: break; }}
switch(num){{ case 50: break; default: break; }}
Add default case.
Java
foo
foo()
Add parentheses.
Kotlin
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
re.sqrt(5)
import re re.sqrt(5)
Import module first.
Python
val a = 97; a = 90
var a = 97; a = 90
Use var for reassignment.
Scala
class Person {{ int b; }} obj.b=5;
class Person {{ public int b; }} obj.b=5;
Make field public.
Java
int[] items = new int[43]; items[43] = 5;
int[] items = new int[43]; if (43 < items.length) items[43] = 5;
Check bounds.
Java
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
<person><desc>hello</desc><age>84</age></person
<person><desc>hello</desc><age>84</age></person>
Add closing >.
XML
result == '79'
result === 79
Use strict equality.
JavaScript
JOIN products ON products.id = products.age
JOIN products ON products.id = products.age
Correct.
SQL
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
if foo = 78
if foo == 78
Use ==.
MATLAB
let val: number | null = null; val.toFixed(77);
let val: number | null = null; if(val!==null) val.toFixed(77);
Null check.
TypeScript
if y = 63
if y == 63
Use ==.
Ruby
'99' + 99
99 + 99
Avoid string coercion.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl