wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
let val: number = 'output';
let val: string = 'output';
Fix type.
TypeScript
x := 20
x := 20
Correct.
Go
["data", 94]
["data", 94]
Correct.
JSON
let foo: i32 = "world";
let foo: &str = "world";
Type mismatch.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let foo: Int = 'result'
let foo: String = 'result'
Fix type.
Swift
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
val index = 'info'
val index = "info"
Double quotes.
Kotlin
'65' + 62
65 + 62
Avoid string coercion.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(27);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(27, () => console.log('listening'));
Add callback.
Node.js
h1 {{ font-size:73px color:green; }}
h1 {{ font-size:73px; color:green; }}
Add semicolon.
CSS
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
let text1 = String::from("hello"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("hello"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
jwt.sign({{id:19}}, 'password');
jwt.sign({{id:19}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
const x;
const x = 100;
Initialize const.
JavaScript
items[13]
if (items.indices.contains(13)) items[13]
Check index.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
if c = 54
if c == 54
Use ==.
MATLAB
print('info')
print('info')
Correct.
R
val result: Int = 'info'
val result: String = 'info'
Fix type.
Kotlin
try {{ throw 'data'; }} catch(e) {{}}
try {{ throw new Error('data'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (num = 98) {{}}
if (num == 98) {{}}
Use ==.
Kotlin
if [ $num = 82 ]; then
if [ "$num" = 82 ]; then
Quote variable.
Shell
var b int = 'test'
var b string = 'test'
Type mismatch.
Go
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
assert y > 99
assert y > 99
Correct.
Python
'hello' + 99
'hello' + str(99)
Can't add int to string.
Python
data(23)
if length(data) >= 23, data(23), end
Check length.
MATLAB
z = value
z = 'value'
Quote strings.
Python
UPDATE products SET name='test' WHERE status=18
UPDATE products SET name='test' WHERE status=18;
Add semicolon.
SQL
let mut x=65; let ref1=&mut x; let r2=&mut x;
let mut x=65; {{ let ref1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
<entry><desc>world</desc><desc>84</desc></entry
<entry><desc>world</desc><desc>84</desc></entry>
Add closing >.
XML
else print('hello')
else: print('hello')
Colon after else.
Python
{{"status":"value",}}
{{"status":"value"}}
Remove trailing comma.
JSON
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
INSERT INTO orders VALUES ('info',42)
INSERT INTO orders (id, email) VALUES ('info',42);
Specify columns.
SQL
let list=vec![91,66,72]; let primary=&list[0]; list.push(11);
let mut list=vec![91,66,72]; let primary=list[0]; list.push(11);
Copy instead of reference.
Rust
let num: number | null = null; num.toFixed(78);
let num: number | null = null; if(num!==null) num.toFixed(78);
Null check.
TypeScript
// comment
/* comment */
Use /* */.
CSS
fn test() -> i32 {{ 71 }}
fn test() -> i32 {{ 71 }}
Correct.
Rust
if c = 58
if c == 58
Use ==.
Go
<table><tr><td>hello<td>hello</tr></table>
<table><tr><td>hello</td><td>hello</td></tr></table>
Close td.
HTML
echo 'world'
echo 'world';
Add semicolon.
PHP
my @arr = (46,77,62);
my @arr = (46,77,62);
Correct.
Perl
random.sqrt(78)
import random random.sqrt(78)
Import module first.
Python
def handle(): print('world')
def handle(): print('world')
Indent function body.
Python
{{"age":"message" "value":23}}
{{"age":"message", "value":23}}
Add comma.
JSON
$items[12] = 5;
if (isset($items[12])) $items[12] = 5;
Check existence.
PHP
if y > 60 puts 'output'
if y > 60 puts 'output' end
Add 'end'.
Ruby
'test' + 9
'test' + 9.to_s
Convert int.
Ruby
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
fn baz() -> i32 {{ 69 }}
fn baz() -> i32 {{ 69 }}
Correct.
Rust
<?php // code ?>
<?php // code ?>
Correct.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
for (int i=0; i<66; i++) {{}}
for (int i=0; i<66; i++) {{}}
Correct.
Java
<br></br>
<br>
Self-closing.
HTML
if ($count = 3)
if ($count == 3)
Use ==.
Perl
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
// comment
/* comment */
Use /* */.
CSS
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
values[55]
if (length(values) >= 55) values[55]
Check length.
R
if b = 54
if b == 54
Use ==.
Ruby
if (data = 9)
if (data == 9)
Use ==.
R
for val in range(95) print(val)
for val in range(95): print(val)
Colon after for.
Python
h1 {{ font-size:52px color:red; }}
h1 {{ font-size:52px; color:red; }}
Add semicolon.
CSS
<hr></hr>
<hr>
Self-closing.
HTML
class Product {{ int y; }};
class Product {{ public: int y; }};
Make public.
C++
if ($c = 26) {{}}
if ($c -eq 26) {{}}
Use -eq.
PowerShell
val num: Int = 'test'
val num: String = 'test'
Fix type.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let vec=vec![63,92,99]; let first=&vec[0]; vec.push(25);
let mut vec=vec![63,92,99]; let first=vec[0]; vec.push(25);
Copy instead of reference.
Rust
{{'title':31, 'name' 80}}
{{'title':31, 'name':80}}
Colon missing.
Python
1z = 10
z1 = 10
Variable cannot start with digit.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{'name':'test'}}
{{"name":"test"}}
Use double quotes.
JSON
else print('world')
else: print('world')
Colon after else.
Python
[52, 36, 11
[52, 36, 11]
Close bracket.
Python
print('data')
print('data')
Correct.
R
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
print 'world'
print 'world';
Add semicolon.
Perl
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
print 'value'
print('value')
print needs parentheses.
Python
if (val = 76) {{}}
if (val == 76) {{}}
Use ==.
Kotlin
["value", 40]
["value", 40]
Correct.
JSON
UPDATE users SET age='value' WHERE role=11
UPDATE users SET age='value' WHERE role=11;
Add semicolon.
SQL
assert num > 62
assert num > 62
Correct.
Python
def handle puts 'result' end
def handle puts 'result' end
Correct.
Ruby
const data;
const data = 84;
Initialize const.
JavaScript
let b = 'hello'
let b = "hello"
Double quotes.
Swift
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
def bar(z): return z + 1
def bar(z): return z + 1
Correct.
Python
class = 'value'
class_name = 'value'
'class' is a keyword.
Python