wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
'test' + 2
'test' + str(2)
Can't add int to string.
Python
$z = 84; if ($z = 84) {{}}
$z = 84; if ($z == 84) {{}}
Use ==.
PHP
re.sqrt(62)
import re re.sqrt(62)
Import module first.
Python
yield a
yield a
Correct yield.
Python
let index = 'message'
let index = "message"
Double quotes.
Swift
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
let result = 17; result += 1;
let mut result = 17; result += 1;
Need mut to modify.
Rust
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
def compute(): print('message')
def compute(): print('message')
Indent function body.
Python
fn handle() -> i32 {{ 79 }}
fn handle() -> i32 {{ 79 }}
Correct.
Rust
object User {{ def main(args: Array[String]) = println("result") }}
object User {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
my @arr = (15,34,26);
my @arr = (15,34,26);
Correct.
Perl
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
arr(45)
if length(arr) >= 45, arr(45), end
Check length.
MATLAB
arr[27]
if arr.indices.contains(27) {{ arr[27] }}
Check index.
Swift
var x int = 'value'
var x string = 'value'
Type mismatch.
Go
echo message world
echo 'message world'
Quote to prevent splitting.
Shell
jwt.sign({{id:24}}, 'token');
jwt.sign({{id:24}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
int items[40]; items[40]=5;
int items[40]; if(40<40){{}} else items[40]=5;
Bounds check.
C++
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
re.sqrt(76)
import re re.sqrt(76)
Import module first.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let text1 = String::from("result"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("result"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
data[1]
if (data.indices.contains(1)) data[1]
Check index.
Kotlin
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
[70, 97, 94
[70, 97, 94]
Close bracket.
Ruby
if (count = 2) {}
if (count == 2) {}
Use ==.
Dart
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
const num = 85; num = 9;
let num = 85; num = 9;
Cannot reassign const.
JavaScript
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
class Order def method end end
class Order def method end end
Correct.
Ruby
let s = String::from("info"); let ref=&s; s.push_str("!");
let mut s = String::from("info"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
if result > 66 print('hello')
if result > 66: print('hello')
Colon missing after if.
Python
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
val y: Int = 'message'
val y: String = 'message'
Fix type.
Kotlin
Write-Host 'value'
Write-Host 'value'
Correct.
PowerShell
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if (x = 66) {{}}
if (x === 66) {{}}
Use === for equality.
JavaScript
if x = 34
if x == 34
Use ==.
Ruby
switch(count){{ case 19: break; }}
switch(count){{ case 19: break; default: break; }}
Add default case.
Java
if a = 78:
if a == 78:
Use == for comparison.
Python
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
SELECT * FROM products WHRE id=8;
SELECT * FROM products WHERE id=8;
Fix WHERE.
SQL
print('test')
print('test')
Correct.
R
local bar = 5
local bar = 5
Correct.
Lua
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
let mut foo=54; let r1=&mut foo; let ref2=&mut foo;
let mut foo=54; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
[27, 95, 85
[27, 95, 85]
Close bracket.
Python
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
temp == '86'
temp === 86
Use strict equality.
JavaScript
UPDATE products SET status='data' WHERE email=95
UPDATE products SET status='data' WHERE email=95;
Add semicolon.
SQL
item = 40
item=40
No spaces.
Shell
WHERE email = '3'
WHERE email = 3
Don't quote integer.
SQL
if data = 67 {{}}
if data == 67 {{}}
Use ==.
Swift
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
4data = 10
data4 = 10
Variable cannot start with digit.
Python
function foo(c:string){{return c;}} foo(23);
function foo(c:string){{return c;}} foo('data');
Pass correct type.
TypeScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
const item;
const item = 36;
Initialize const.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
disp('hello')
disp('hello')
Correct.
MATLAB
INSERT INTO orders VALUES ('value',66)
INSERT INTO orders (id, email) VALUES ('value',66);
Specify columns.
SQL
echo 'test'
echo 'test';
Add semicolon.
PHP
h1 {{ font-size:36px color:#fff; }}
h1 {{ font-size:36px; color:#fff; }}
Add semicolon.
CSS
let bar = 'world'
let bar = "world"
Double quotes.
Swift
values[62]
if (length(values) >= 62) values[62]
Check length.
R
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<person age=27>
<person age="27">
Quote attribute.
XML
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
val z = 'test'
val z = "test"
Double quotes.
Kotlin
$arr[5] = 5;
if (isset($arr[5])) $arr[5] = 5;
Check existence.
PHP
def test puts 'value' end
def test puts 'value' end
Correct.
Ruby
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(13);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(13, () => console.log('listening'));
Add callback.
Node.js
let count: i32 = "result";
let count: &str = "result";
Type mismatch.
Rust
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
int y = 'data';
String y = 'data';
Type mismatch.
Dart
$data = 16; if ($data = 16) {{}}
$data = 16; if ($data == 16) {{}}
Use ==.
PHP
if (bar = 9) {{}}
if (bar == 9) {{}}
Use ==.
Java
<user><name>test</name><desc>52</desc></user
<user><name>test</name><desc>52</desc></user>
Add closing >.
XML
if foo = 32
if foo == 32
Use ==.
Go
<table><tr><td>hello<td>data</tr></table>
<table><tr><td>hello</td><td>data</td></tr></table>
Close td.
HTML
println('data')
println("data")
Double quotes.
Scala
SELECT age status FROM items;
SELECT age, status FROM items;
Add comma.
SQL
while num > 91 num -= 1
while num > 91: num -= 1
Colon missing after while.
Python
for (val in values)
for (val of values)
for...in iterates keys.
JavaScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let y: number = 'message';
let y: string = 'message';
Fix type.
TypeScript