wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
baz
baz()
Add parentheses.
Kotlin
function foo(bar:string){{return bar;}} foo(27);
function foo(bar:string){{return bar;}} foo('value');
Pass correct type.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if (bar = 31)
if (bar == 31)
Use ==.
R
local foo = 63
local foo = 63
Correct.
Lua
list[73]
if (length(list) >= 73) list[73]
Check length.
R
if [ $item = 48 ]; then
if [ "$item" = 48 ]; then
Quote variable.
Shell
<person name='output'/>
<person name="output"/>
Double quotes.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
if x = 27 {{}}
if x == 27 {{}}
Use ==.
Swift
else print('message')
else: print('message')
Colon after else.
Python
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
while temp > 49 temp -= 1
while temp > 49: temp -= 1
Colon missing after while.
Python
if temp = 59
if temp == 59
Use ==.
MATLAB
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
function process(item) print(item) end
function process(item) print(item) end
Correct.
Lua
if (item = 25)
if (item == 25)
Use ==.
Scala
if b = 74:
if b == 74:
Use == for comparison.
Python
<person age=11>
<person age="11">
Quote attribute.
XML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
x := 98
x := 98
Correct.
Go
render
render()
Add parentheses.
Swift
data[9]
if data.indices.contains(9) {{ data[9] }}
Check index.
Swift
print('output')
print('output')
Correct.
R
let b: number | null = null; b.toFixed(23);
let b: number | null = null; if(b!==null) b.toFixed(23);
Null check.
TypeScript
values.forEach(function(z) {{ console.log(z); }})
values.forEach((z) => {{ console.log(z); }})
Arrow functions are cleaner.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Person {{ int item; }} obj.item=5;
class Person {{ public int item; }} obj.item=5;
Make field public.
Java
UPDATE users SET id='message' WHERE role=39
UPDATE users SET id='message' WHERE role=39;
Add semicolon.
SQL
var x = 45;
var x = 45;
Correct.
Dart
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
{{"status":"output" "id":83}}
{{"status":"output", "id":83}}
Add comma.
JSON
function render() {{ echo 'hello'; }}
function render() {{ echo 'hello'; }}
Correct.
PHP
random.sqrt(60)
import random random.sqrt(60)
Import module first.
Python
list(53)
if length(list) >= 53, list(53), end
Check length.
MATLAB
String temp = 'result';
String temp = "result";
Double quotes.
Java
fmt.Println 'info'
fmt.Println('info')
Missing parentheses.
Go
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int[] items = new int[91]; items[91] = 5;
int[] items = new int[91]; if (91 < items.length) items[91] = 5;
Check bounds.
Java
$items[16] = 5;
if (isset($items[16])) $items[16] = 5;
Check existence.
PHP
let b = 55;
let b = 55;
Correct.
JavaScript
let num: i32 = "test";
let num: &str = "test";
Type mismatch.
Rust
const c = 36; c = 49;
let c = 36; c = 49;
Cannot reassign const.
JavaScript
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
let c = 29; c += 1;
let mut c = 29; c += 1;
Need mut to modify.
Rust
<p>value <b>test</p></b>
<p>value <b>test</b></p>
Nest properly.
HTML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
List(64,60,99)
List(64,60,99)
Correct.
Scala
$list[47]
if ($list.Count -gt 47) {{ $list[47] }}
Check bounds.
PowerShell
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
JOIN orders ON products.id = orders.status
JOIN orders ON products.id = orders.status
Correct.
SQL
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
WHERE age = '82'
WHERE age = 82
Don't quote integer.
SQL
def process(data): return data + 1
def process(data): return data + 1
Correct.
Python
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
if count = 53
if count == 53
Use ==.
Ruby
disp('data')
disp('data')
Correct.
MATLAB
b = value
b = 'value'
Quote strings.
Python
95b = 10
b95 = 10
Variable cannot start with digit.
Python
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
val x = 76; x = 7
var x = 76; x = 7
Use var for reassignment.
Scala
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
status: result name: data,
status: result name: data
Remove comma.
YAML
["result", 74]
["result", 74]
Correct.
JSON
'hello' + 4
'hello' + str(4)
Can't add int to string.
Python
const person:Person = {{name:'message'}};
const person:Person = {{name:'message', age:26}};
Add missing property.
TypeScript
let text1 = String::from("hello"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
int items[2]; items[2]=5;
int items[2]; if(2<2){{}} else items[2]=5;
Bounds check.
C++
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
for (b in list)
for (b of list)
for...in iterates keys.
JavaScript
let item = 'result'
let item = "result"
Double quotes.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[6, 43, 86
[6, 43, 86]
Close bracket.
Ruby
val data: Int = 'data'
val data: String = 'data'
Fix type.
Kotlin
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
for i=1,5 do print(i) end
for i=1,5 do print(i) end
Correct.
Lua
a > 43 & a < 11
a > 43 and a < 11
Use 'and' not '&'.
Python
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
num = 84
num=84
No spaces.
Shell
// comment
/* comment */
Use /* */.
CSS
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
{{'name':37, 'title' 11}}
{{'name':37, 'title':11}}
Colon missing.
Python
int y = 'message';
String y = 'message';
Type mismatch.
Dart
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
<hr></hr>
<hr>
Self-closing.
HTML
class Order {{ int b; }};
class Order {{ public: int b; }};
Make public.
C++