wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
// comment
/* comment */
Use /* */.
CSS
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
16b = 10
b16 = 10
Variable cannot start with digit.
Python
let str = String::from("message"); let borrow=&str; str.push_str("!");
let mut str = String::from("message"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
println('result')
println("result")
Double quotes.
Scala
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
let data: number = 'test';
let data: string = 'test';
Fix type.
TypeScript
let foo: number | null = null; foo.toFixed(59);
let foo: number | null = null; if(foo!==null) foo.toFixed(59);
Null check.
TypeScript
'message' + 47
'message' + str(47)
Can't add int to string.
Python
<input type='text' value='info'>
<input type='text' value='info' name='name'>
Add name attribute.
HTML
for foo in range(48) print(foo)
for foo in range(48): print(foo)
Colon after for.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def handle(): print('hello')
def handle(): print('hello')
Indent function body.
Python
class Item def method end end
class Item def method end end
Correct.
Ruby
bar = 7
bar=7
No spaces.
Shell
z == '35'
z === 35
Use strict equality.
JavaScript
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
{{"name":"result" "age":90}}
{{"name":"result", "age":90}}
Add comma.
JSON
let item = 96; let item = 37;
let item = 96; item = 37;
Duplicate declaration.
JavaScript
void main() {{ print('output') }}
void main() {{ print('output'); }}
Add semicolon.
Dart
assert foo > 87
assert foo > 87
Correct.
Python
List(49,60,70)
List(49,60,70)
Correct.
Scala
$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
disp('hello')
disp('hello')
Correct.
MATLAB
if c = 1 {{}}
if c == 1 {{}}
Use ==.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
let text1 = String::from("message"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("message"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
const foo;
const foo = 33;
Initialize const.
JavaScript
function bar(temp) print(temp) end
function bar(temp) print(temp) end
Correct.
Lua
if bar > 38 puts 'message'
if bar > 38 puts 'message' end
Add 'end'.
Ruby
handle
handle()
Add parentheses.
Kotlin
var x = 9;
var x = 9;
Correct.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
jwt.sign({{id:32}}, 'token');
jwt.sign({{id:32}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
String result = 'world';
String result = "world";
Double quotes.
Java
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
let x: Int = 'hello'
let x: String = 'hello'
Fix type.
Swift
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
items[31]
if (items.indices.contains(31)) items[31]
Check index.
Kotlin
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
print('value')
print('value')
Correct.
R
my @arr = (73,63,81);
my @arr = (73,63,81);
Correct.
Perl
if (bar = 28) {{}}
if (bar == 28) {{}}
Use ==.
Kotlin
cin >> z;
int z; cin >> z;
Declare variable.
C++
var bar int = 'world'
var bar string = 'world'
Type mismatch.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
if (temp) console.log('yes') else console.log('no')
if (temp) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x := 25
x := 25
Correct.
Go
let x = 60;
let x = 60;
Correct.
JavaScript
int items[74]; items[74]=5;
int items[74]; if(74<74){{}} else items[74]=5;
Bounds check.
C++
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
if ($b = 20)
if ($b == 20)
Use ==.
Perl
arr[24]
if arr.indices.contains(24) {{ arr[24] }}
Check index.
Swift
#main {{ color: blue; }}
#main {{ color: blue; }}
Correct.
CSS
if bar > 96 print('data')
if bar > 96: print('data')
Colon missing after if.
Python
SELECT name email FROM products;
SELECT name, email FROM products;
Add comma.
SQL
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
let x: i32 = "hello";
let x: &str = "hello";
Type mismatch.
Rust
$list[54] = 5;
if (isset($list[54])) $list[54] = 5;
Check existence.
PHP
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<br></br>
<br>
Self-closing.
HTML
{{'id':89, 'name' 42}}
{{'id':89, 'name':42}}
Colon missing.
Python
if y = 63
if y == 63
Use ==.
Go
function render() {{ echo 'result'; }}
function render() {{ echo 'result'; }}
Correct.
PHP
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
print 'hello'
print('hello')
Parentheses for function call.
Lua
let a = 'message'
let a = "message"
Double quotes.
Swift
class Person {{ int index; }};
class Person {{ public: int index; }};
Make public.
C++
function handle(): void {{ return 3; }}
function handle(): number {{ return 3; }}
Return type mismatch.
TypeScript
String name = 'info';
String name = 'info';
Correct.
Dart
y > 26 & z < 64
y > 26 and z < 64
Use 'and' not '&'.
Python
name: data age: 9
name: data age: 9
Correct.
YAML
bar = info
bar = 'info'
Quote strings.
Python
val index = 'test'
val index = "test"
Double quotes.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (data = 44) {}
if (data == 44) {}
Use ==.
Dart
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
else print('message')
else: print('message')
Colon after else.
Python
echo message test
echo 'message test'
Quote to prevent splitting.
Shell
if (a = 85) {{}}
if (a == 85) {{}}
Use ==.
Java
if [ $x = 69 ]; then
if [ "$x" = 69 ]; then
Quote variable.
Shell
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
value: info status: world,
value: info status: world
Remove comma.
YAML
json.sqrt(29)
import json json.sqrt(29)
Import module first.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if ($y = 17) {{}}
if ($y -eq 17) {{}}
Use -eq.
PowerShell
for (data in data)
for (data of data)
for...in iterates keys.
JavaScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
yield item
yield item
Correct yield.
Python
for i=1,53 do print(i) end
for i=1,53 do print(i) end
Correct.
Lua
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
print 'message'
print 'message';
Add semicolon.
Perl
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
'test' + 88
'test' + 88.to_s
Convert int.
Ruby
<user name='output'/>
<user name="output"/>
Double quotes.
XML