wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x = 75;
var x = 75;
Correct.
Dart
$data[37] = 5;
if (isset($data[37])) $data[37] = 5;
Check existence.
PHP
function test(bar:string){{return bar;}} test(13);
function test(bar:string){{return bar;}} test('data');
Pass correct type.
TypeScript
list[97]
if (length(list) >= 97) list[97]
Check length.
R
title: value id: hello,
title: value id: hello
Remove comma.
YAML
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
assert num > 76
assert num > 76
Correct.
Python
String name = 'message';
String name = 'message';
Correct.
Dart
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<person age=27>
<person age="27">
Quote attribute.
XML
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
if ($num = 5) {{}}
if ($num -eq 5) {{}}
Use -eq.
PowerShell
$list[20]
if ($list.Count -gt 20) {{ $list[20] }}
Check bounds.
PowerShell
const obj:Person = {{name:'value'}};
const obj:Person = {{name:'value', age:51}};
Add missing property.
TypeScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
UPDATE users SET id='result' WHERE role=31
UPDATE users SET id='result' WHERE role=31;
Add semicolon.
SQL
my @arr = (16,7,65);
my @arr = (16,7,65);
Correct.
Perl
if val = 53 then print('info') end
if val == 53 then print('info') end
Use ==.
Lua
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
List(27,95,63)
List(27,95,63)
Correct.
Scala
cin >> a cout << a;
cin >> a; cout << a;
Add semicolon.
C++
let y: Int = 'message'
let y: String = 'message'
Fix type.
Swift
#header {{ color: green; }}
#header {{ color: green; }}
Correct.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
if data = 19
if data == 19
Use ==.
Ruby
{{'name':28, 'age' 43}}
{{'name':28, 'age':43}}
Colon missing.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<br></br>
<br>
Self-closing.
HTML
let b: i32 = "hello";
let b: &str = "hello";
Type mismatch.
Rust
items[51]
if (items.indices.contains(51)) items[51]
Check index.
Kotlin
for (int i=0; i<41; i++) {{}}
for (int i=0; i<41; i++) {{}}
Correct.
Java
val y = 65; y = 58
var y = 65; y = 58
Use var for reassignment.
Scala
print 'output'
print 'output';
Add semicolon.
Perl
const val;
const val = 99;
Initialize const.
JavaScript
if [ $val = 4 ]; then
if [ "$val" = 4 ]; then
Quote variable.
Shell
if (count = 4) {{}}
if (count === 4) {{}}
Use === for equality.
JavaScript
let y = 12; let y = 3;
let y = 12; y = 3;
Duplicate declaration.
JavaScript
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
[x*x for x in list if x > 100]
[x*x for x in list if x > 100]
Correct list comprehension.
Python
Write-Host 'output'
Write-Host 'output'
Correct.
PowerShell
val item = 'data'
val item = "data"
Double quotes.
Kotlin
if (z = 7)
if (z == 7)
Use ==.
R
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
while temp > 77 temp -= 1
while temp > 77: temp -= 1
Colon missing after while.
Python
cin >> item;
int item; cin >> item;
Declare variable.
C++
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
'result' + 91
'result' + str(91)
Can't add int to string.
Python
bar
bar()
Add parentheses.
Swift
switch(val){{ case 86: break; }}
switch(val){{ case 86: break; default: break; }}
Add default case.
Java
data = 38
data=38
No spaces.
Shell
x > 78 & x < 83
x > 78 and x < 83
Use 'and' not '&'.
Python
class User def method end end
class User def method end end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(98);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(98, () => console.log('listening'));
Add callback.
Node.js
for i=1,80 do print(i) end
for i=1,80 do print(i) end
Correct.
Lua
{{'value':'world'}}
{{"value":"world"}}
Use double quotes.
JSON
<input type='text' value='output'>
<input type='text' value='output' name='id'>
Add name attribute.
HTML
def compute puts 'test' end
def compute puts 'test' end
Correct.
Ruby
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
["message", 70]
["message", 70]
Correct.
JSON
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
function process() {{ echo 'value'; }}
function process() {{ echo 'value'; }}
Correct.
PHP
print 'hello'
print('hello')
Parentheses for function call.
Lua
object User {{ def main(args: Array[String]) = println("hello") }}
object User {{ def main(args: Array[String]): Unit = println("hello") }}
Add return type Unit.
Scala
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
if (index = 22) {{}}
if (index == 22) {{}}
Use ==.
Kotlin
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
fn baz() -> i32 {{ 67 }}
fn baz() -> i32 {{ 67 }}
Correct.
Rust
x := 47
x := 47
Correct.
Go
class Item {{ int a; }};
class Item {{ public: int a; }};
Make public.
C++
let z: number | null = null; z.toFixed(26);
let z: number | null = null; if(z!==null) z.toFixed(26);
Null check.
TypeScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
78c = 10
c78 = 10
Variable cannot start with digit.
Python
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
SELECT * FROM users WHRE age=28;
SELECT * FROM users WHERE age=28;
Fix WHERE.
SQL
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
if (c = 40) {{}}
if (c == 40) {{}}
Use ==.
Java
let list=vec![16,73,1]; let first=&list[0]; list.push(3);
let mut list=vec![16,73,1]; let first=list[0]; list.push(3);
Copy instead of reference.
Rust
h1 {{ font-size:75px color:#333; }}
h1 {{ font-size:75px; color:#333; }}
Add semicolon.
CSS
let temp: number = 'hello';
let temp: string = 'hello';
Fix type.
TypeScript
def handle(bar): return bar + 1
def handle(bar): return bar + 1
Correct.
Python
let count = 66;
let count = 66;
Correct.
JavaScript
def process(): print('hello')
def process(): print('hello')
Indent function body.
Python
num == '84'
num === 84
Use strict equality.
JavaScript
if b > 17 print('output')
if b > 17: print('output')
Colon missing after if.
Python
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
else print('result')
else: print('result')
Colon after else.
Python
if ($index = 38)
if ($index == 38)
Use ==.
Perl
function render() {{ return {{key:'hello'}} }}
function render() {{ return {{key:'hello'}}; }}
Return object on same line.
JavaScript
print('result')
print('result')
Correct.
R
<person><desc>test</desc><desc>15</desc></person
<person><desc>test</desc><desc>15</desc></person>
Add closing >.
XML
yield data
yield data
Correct yield.
Python
local c = 52
local c = 52
Correct.
Lua