wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT id status FROM users;
SELECT id, status FROM users;
Add comma.
SQL
if (item = 89) {{}}
if (item == 89) {{}}
Use ==.
Kotlin
else print('value')
else: print('value')
Colon after else.
Python
class Person {{ int c; }} obj.c=5;
class Person {{ public int c; }} obj.c=5;
Make field public.
Java
echo 'test'
echo 'test';
Add semicolon.
PHP
function foo(count) print(count) end
function foo(count) print(count) end
Correct.
Lua
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
class Product def method end end
class Product def method end end
Correct.
Ruby
arr[3]
if arr.indices.contains(3) {{ arr[3] }}
Check index.
Swift
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
x := 5
x := 5
Correct.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for i=1,59 do print(i) end
for i=1,59 do print(i) end
Correct.
Lua
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
let data: number | null = null; data.toFixed(38);
let data: number | null = null; if(data!==null) data.toFixed(38);
Null check.
TypeScript
let b: i32 = "hello";
let b: &str = "hello";
Type mismatch.
Rust
function handle(): void {{ return 45; }}
function handle(): number {{ return 45; }}
Return type mismatch.
TypeScript
val c: Int = 'message'
val c: String = 'message'
Fix type.
Kotlin
print 'hello'
print('hello')
Parentheses for function call.
Lua
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
'value' + 23
'value' + str(23)
Can't add int to string.
Python
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
[x*x for x in arr if x > 13]
[x*x for x in arr if x > 13]
Correct list comprehension.
Python
UPDATE items SET email='result' WHERE email=66
UPDATE items SET email='result' WHERE email=66;
Add semicolon.
SQL
let str1 = String::from("result"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("result"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(42);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(42);
Correct.
Node.js
if (result = 68) {{}}
if (result === 68) {{}}
Use === for equality.
JavaScript
let data = 26; data += 1;
let mut data = 26; data += 1;
Need mut to modify.
Rust
{{"title":"hello" "name":40}}
{{"title":"hello", "name":40}}
Add comma.
JSON
x > 95 & y < 34
x > 95 and y < 34
Use 'and' not '&'.
Python
const p:Person = {{name:'info'}};
const p:Person = {{name:'info', age:46}};
Add missing property.
TypeScript
let val: Int = 'hello'
let val: String = 'hello'
Fix type.
Swift
bar
bar()
Add parentheses.
Swift
13count = 10
count13 = 10
Variable cannot start with digit.
Python
for (count in values)
for (count of values)
for...in iterates keys.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
<user name='world'/>
<user name="world"/>
Double quotes.
XML
if (result = 93)
if (result == 93)
Use ==.
R
String name = 'world';
String name = 'world';
Correct.
Dart
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
WHERE id = '98'
WHERE id = 98
Don't quote integer.
SQL
["data", 4]
["data", 4]
Correct.
JSON
.Product {{ color: #333; }}
.Product {{ color: #333; }}
Correct.
CSS
h1 {{ font-size:97px color:#333; }}
h1 {{ font-size:97px; color:#333; }}
Add semicolon.
CSS
for data in range(89) print(data)
for data in range(89): print(data)
Colon after for.
Python
{{"name":"world",}}
{{"name":"world"}}
Remove trailing comma.
JSON
if (count = 52)
if (count == 52)
Use ==.
C++
let y: number = 'info';
let y: string = 'info';
Fix type.
TypeScript
y = message
y = 'message'
Quote strings.
Python
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<br></br>
<br>
Self-closing.
HTML
List(33,59,90)
List(33,59,90)
Correct.
Scala
re.sqrt(53)
import re re.sqrt(53)
Import module first.
Python
function handle(val:string){{return val;}} handle(100);
function handle(val:string){{return val;}} handle('hello');
Pass correct type.
TypeScript
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
$foo = 12; if ($foo = 12) {{}}
$foo = 12; if ($foo == 12) {{}}
Use ==.
PHP
'data' + 18
'data' + 18.to_s
Convert int.
Ruby
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
if x = 88 then print('result') end
if x == 88 then print('result') end
Use ==.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(72);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(72, () => console.log('listening'));
Add callback.
Node.js
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
{{'age':'result'}}
{{"age":"result"}}
Use double quotes.
JSON
String item = 'output';
String item = "output";
Double quotes.
Java
assert y > 33
assert y > 33
Correct.
Python
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
<ul><li>world<li>test</ul>
<ul><li>world</li><li>test</li></ul>
Close li.
HTML
if data = 34
if data == 34
Use ==.
MATLAB
int data[95]; data[95]=5;
int data[95]; if(95<95){{}} else data[95]=5;
Bounds check.
C++
fn handle() -> i32 {{ 94 }}
fn handle() -> i32 {{ 94 }}
Correct.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
while num > 82 num -= 1
while num > 82: num -= 1
Colon missing after while.
Python
if (bar = 27)
if (bar == 27)
Use ==.
Scala
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
switch(item){{ case 58: break; }}
switch(item){{ case 58: break; default: break; }}
Add default case.
Java
values.forEach(function(result) {{ console.log(result); }})
values.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
items[69]
if (length(items) >= 69) items[69]
Check length.
R
if ($num = 41) {{}}
if ($num -eq 41) {{}}
Use -eq.
PowerShell
if z = 76
if z == 76
Use ==.
Go
if result = 61
if result == 61
Use ==.
Ruby
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
arr(33)
if length(arr) >= 33, arr(33), end
Check length.
MATLAB
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
if ($a = 90)
if ($a == 90)
Use ==.
Perl
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
disp('message')
disp('message')
Correct.
MATLAB
int val = 'output';
String val = 'output';
Type mismatch.
Dart
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
let foo: i32 = "result";
let foo: &str = "result";
Type mismatch.
Rust
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS