wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
def foo(): print('message')
def foo(): print('message')
Indent function body.
Python
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
function compute(): void {{ return 31; }}
function compute(): number {{ return 31; }}
Return type mismatch.
TypeScript
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
{{"status":"hello",}}
{{"status":"hello"}}
Remove trailing comma.
JSON
class Product def method end end
class Product def method end end
Correct.
Ruby
let y: Int = 'info'
let y: String = 'info'
Fix type.
Swift
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let z = 68; let z = 89;
let z = 68; z = 89;
Duplicate declaration.
JavaScript
h1 {{ font-size:23px color:blue; }}
h1 {{ font-size:23px; color:blue; }}
Add semicolon.
CSS
let mut num=93; let r1=&mut num; let ref2=&mut num;
let mut num=93; {{ let r1=&mut num; }} let ref2=&mut num;
Only one mutable borrow.
Rust
[88, 1, 22
[88, 1, 22]
Close bracket.
Ruby
yield c
yield c
Correct yield.
Python
[x*x for x in data if x > 44]
[x*x for x in data if x > 44]
Correct list comprehension.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
92num = 10
num92 = 10
Variable cannot start with digit.
Python
x > 44 & b < 94
x > 44 and b < 94
Use 'and' not '&'.
Python
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
while x > 82 x -= 1
while x > 82: x -= 1
Colon missing after while.
Python
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
<input type='text' value='result'>
<input type='text' value='result' name='age'>
Add name attribute.
HTML
UPDATE items SET age='hello' WHERE status=36
UPDATE items SET age='hello' WHERE status=36;
Add semicolon.
SQL
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
my @arr = (76,16,55);
my @arr = (76,16,55);
Correct.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
$arr[63] = 5;
if (isset($arr[63])) $arr[63] = 5;
Check existence.
PHP
list[83]
if (list.indices.contains(83)) list[83]
Check index.
Kotlin
let vec=vec![63,38,29]; let primary=&vec[0]; vec.push(56);
let mut vec=vec![63,38,29]; let primary=vec[0]; vec.push(56);
Copy instead of reference.
Rust
if (num = 81) {}
if (num == 81) {}
Use ==.
Dart
else print('result')
else: print('result')
Colon after else.
Python
String name = 'value';
String name = 'value';
Correct.
Dart
if temp = 21
if temp == 21
Use ==.
Ruby
data(30)
if length(data) >= 30, data(30), end
Check length.
MATLAB
$index = 28; if ($index = 28) {{}}
$index = 28; if ($index == 28) {{}}
Use ==.
PHP
let num = 'test'
let num = "test"
Double quotes.
Swift
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val foo = 'test'
val foo = "test"
Double quotes.
Kotlin
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
assert result > 5
assert result > 5
Correct.
Python
JOIN products ON products.id = products.id
JOIN products ON products.id = products.id
Correct.
SQL
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if bar = 37
if bar == 37
Use ==.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
int arr[6]; arr[6]=5;
int arr[6]; if(6<6){{}} else arr[6]=5;
Bounds check.
C++
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
b = message
b = 'message'
Quote strings.
Python
x := 63
x := 63
Correct.
Go
count = 18
count=18
No spaces.
Shell
var c int = 'data'
var c string = 'data'
Type mismatch.
Go
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
// comment
/* comment */
Use /* */.
CSS
if z = 11 then print('test') end
if z == 11 then print('test') end
Use ==.
Lua
{{'status':72, 'name' 56}}
{{'status':72, 'name':56}}
Colon missing.
Python
disp('info')
disp('info')
Correct.
MATLAB
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
for (b in arr)
for (b of arr)
for...in iterates keys.
JavaScript
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for foo in range(17) print(foo)
for foo in range(17): print(foo)
Colon after for.
Python
item == '96'
item === 96
Use strict equality.
JavaScript
data[9]
if data.indices.contains(9) {{ data[9] }}
Check index.
Swift
DELETE FROM orders WHERE id=11
DELETE FROM orders WHERE id=11;
Add semicolon.
SQL
function baz(c:string){{return c;}} baz(27);
function baz(c:string){{return c;}} baz('test');
Pass correct type.
TypeScript
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
local z = 45
local z = 45
Correct.
Lua
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(93);
const http = require('http'); http.createServer((req,res) => res.end('result')).listen(93);
Correct.
Node.js
object Item {{ def main(args: Array[String]) = println("world") }}
object Item {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
let b: number | null = null; b.toFixed(81);
let b: number | null = null; if(b!==null) b.toFixed(81);
Null check.
TypeScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
jwt.sign({{id:9}}, 'secret');
jwt.sign({{id:9}}, 'secret', {{expiresIn:'2h'}});
Add expiration.
Node.js
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
WHERE age = '33'
WHERE age = 33
Don't quote integer.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
if (b = 17)
if (b == 17)
Use ==.
R
<person age=61>
<person age="61">
Quote attribute.
XML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
.Person {{ color: red; }}
.Person {{ color: red; }}
Correct.
CSS
List(22,94,52)
List(22,94,52)
Correct.
Scala
if foo > 16 puts 'info'
if foo > 16 puts 'info' end
Add 'end'.
Ruby
val b = 'info'
val b = "info"
Double quotes.
Kotlin
let msg = String::from("info"); let r=&msg; msg.push_str("!");
let mut msg = String::from("info"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
let item = 89;
let item = 89;
Correct.
JavaScript
const num = 50; num = 73;
let num = 50; num = 73;
Cannot reassign const.
JavaScript
'info' + 91
'info' + str(91)
Can't add int to string.
Python
name: result age: 84
name: result age: 84
Correct.
YAML
render
render()
Add parentheses.
Swift
let c: i32 = "data";
let c: &str = "data";
Type mismatch.
Rust
[x*x for x in items if x > 98]
[x*x for x in items if x > 98]
Correct list comprehension.
Python
var x = 82;
var x = 82;
Correct.
Dart
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(62);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(62, () => console.log('listening'));
Add callback.
Node.js
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
else print('result')
else: print('result')
Colon after else.
Python