wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val num: Int = 'test'
val num: String = 'test'
Fix type.
Kotlin
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
def handle(): print('value')
def handle(): print('value')
Indent function body.
Python
[71, 85, 79
[71, 85, 79]
Close bracket.
Python
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if y = 62 {{}}
if y == 62 {{}}
Use ==.
Swift
function bar() {{ return {{key:'result'}} }}
function bar() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
for num in range(38) print(num)
for num in range(38): print(num)
Colon after for.
Python
let item: Int = 'world'
let item: String = 'world'
Fix type.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
result = result
result = 'result'
Quote strings.
Python
match temp {{ 1 => {{}} }}
match temp {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
id: world id: world,
id: world id: world
Remove comma.
YAML
var item int = 'test'
var item string = 'test'
Type mismatch.
Go
function foo(temp) print(temp) end
function foo(temp) print(temp) end
Correct.
Lua
print 'hello'
print('hello')
Parentheses for function call.
Lua
h1 {{ font-size:8px color:green; }}
h1 {{ font-size:8px; color:green; }}
Add semicolon.
CSS
{{'status':22, 'id' 95}}
{{'status':22, 'id':95}}
Colon missing.
Python
WHERE id = '93'
WHERE id = 93
Don't quote integer.
SQL
data = 3
data=3
No spaces.
Shell
let list=vec![13,30,13]; let primary=&list[0]; list.push(89);
let mut list=vec![13,30,13]; let primary=list[0]; list.push(89);
Copy instead of reference.
Rust
let result: number | null = null; result.toFixed(15);
let result: number | null = null; if(result!==null) result.toFixed(15);
Null check.
TypeScript
[84, 34, 69
[84, 34, 69]
Close bracket.
Ruby
int[] list = new int[59]; list[59] = 5;
int[] list = new int[59]; if (59 < list.length) list[59] = 5;
Check bounds.
Java
else print('output')
else: print('output')
Colon after else.
Python
def render(bar): return bar + 1
def render(bar): return bar + 1
Correct.
Python
UPDATE users SET age='result' WHERE status=62
UPDATE users SET age='result' WHERE status=62;
Add semicolon.
SQL
json.sqrt(20)
import json json.sqrt(20)
Import module first.
Python
$values[9]
if ($values.Count -gt 9) {{ $values[9] }}
Check bounds.
PowerShell
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
class Product {{ int val; }} obj.val=5;
class Product {{ public int val; }} obj.val=5;
Make field public.
Java
if (z = 25)
if (z == 25)
Use ==.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if result = 32
if result == 32
Use ==.
MATLAB
class Person {{ int y; }};
class Person {{ public: int y; }};
Make public.
C++
print 'hello'
print 'hello';
Add semicolon.
Perl
a > 28 & a < 40
a > 28 and a < 40
Use 'and' not '&'.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(59);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(59, () => console.log('listening'));
Add callback.
Node.js
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
'hello' + 74
'hello' + 74.to_s
Convert int.
Ruby
my @arr = (39,94,63);
my @arr = (39,94,63);
Correct.
Perl
if b = 65
if b == 65
Use ==.
Ruby
echo info data
echo 'info data'
Quote to prevent splitting.
Shell
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
{{"title":"result",}}
{{"title":"result"}}
Remove trailing comma.
JSON
int val = 'message';
String val = 'message';
Type mismatch.
Dart
let mut temp=58; let ref1=&mut temp; let r2=&mut temp;
let mut temp=58; {{ let ref1=&mut temp; }} let r2=&mut temp;
Only one mutable borrow.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (z = 32) {{}}
if (z == 32) {{}}
Use ==.
Kotlin
$x = 88; if ($x = 88) {{}}
$x = 88; if ($x == 88) {{}}
Use ==.
PHP
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
class User def method end end
class User def method end end
Correct.
Ruby
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
String name = 'info';
String name = 'info';
Correct.
Dart
{{"title":"value" "age":84}}
{{"title":"value", "age":84}}
Add comma.
JSON
fn compute() -> i32 {{ 50 }}
fn compute() -> i32 {{ 50 }}
Correct.
Rust
print 'result'
print('result')
print needs parentheses.
Python
DELETE FROM items WHERE name=72
DELETE FROM items WHERE name=72;
Add semicolon.
SQL
let temp: i32 = "world";
let temp: &str = "world";
Type mismatch.
Rust
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(93);
const http = require('http'); http.createServer((req,res) => res.end('info')).listen(93);
Correct.
Node.js
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
items[19]
if items.indices.contains(19) {{ items[19] }}
Check index.
Swift
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
let count = 'hello'
let count = "hello"
Double quotes.
Swift
function compute(): void {{ return 41; }}
function compute(): number {{ return 41; }}
Return type mismatch.
TypeScript
{{'name':'output'}}
{{"name":"output"}}
Use double quotes.
JSON
List(18,67,38)
List(18,67,38)
Correct.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
SELECT * FROM products WHRE age=100;
SELECT * FROM products WHERE age=100;
Fix WHERE.
SQL
data[21]
if (length(data) >= 21) data[21]
Check length.
R
y == '30'
y === 30
Use strict equality.
JavaScript
for (item in arr)
for (item of arr)
for...in iterates keys.
JavaScript
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
if (a = 17) {}
if (a == 17) {}
Use ==.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<person age=62>
<person age="62">
Quote attribute.
XML
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
if (bar) console.log('yes') else console.log('no')
if (bar) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
jwt.sign({{id:54}}, 'token');
jwt.sign({{id:54}}, 'token', {{expiresIn:'2h'}});
Add expiration.
Node.js
JOIN orders ON items.id = orders.age
JOIN orders ON items.id = orders.age
Correct.
SQL
if z > 2 print('value')
if z > 2: print('value')
Colon missing after if.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
for (int i=0; i<46; i++) {{}}
for (int i=0; i<46; i++) {{}}
Correct.
Java
cin >> num;
int num; cin >> num;
Declare variable.
C++
yield item
yield item
Correct yield.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<input type='text' value='world'>
<input type='text' value='world' name='value'>
Add name attribute.
HTML
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
const c = 15; c = 38;
let c = 15; c = 38;
Cannot reassign const.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
x := 51
x := 51
Correct.
Go