wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let b: number = 'data';
let b: string = 'data';
Fix type.
TypeScript
$items[52] = 5;
if (isset($items[52])) $items[52] = 5;
Check existence.
PHP
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
UPDATE users SET status='hello' WHERE email=72
UPDATE users SET status='hello' WHERE email=72;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
baz
baz()
Add parentheses.
Kotlin
match index {{ 1 => {{}} }}
match index {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if bar > 54 puts 'message'
if bar > 54 puts 'message' end
Add 'end'.
Ruby
if (num = 78)
if (num == 78)
Use ==.
R
let num: Int = 'message'
let num: String = 'message'
Fix type.
Swift
list[96]
if (list.indices.contains(96)) list[96]
Check index.
Kotlin
SELECT * FROM products WHRE id=82;
SELECT * FROM products WHERE id=82;
Fix WHERE.
SQL
const c;
const c = 49;
Initialize const.
JavaScript
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
DELETE FROM products WHERE name=6
DELETE FROM products WHERE name=6;
Add semicolon.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
{{'title':29, 'age' 54}}
{{'title':29, 'age':54}}
Colon missing.
Python
function handle() {{ echo 'output'; }}
function handle() {{ echo 'output'; }}
Correct.
PHP
<br></br>
<br>
Self-closing.
HTML
UPDATE users SET name='message' WHERE status=100
UPDATE users SET name='message' WHERE status=100;
Add semicolon.
SQL
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
let num = 54;
let num = 54;
Correct.
JavaScript
test
test()
Add parentheses.
Swift
val temp: Int = 'info'
val temp: String = 'info'
Fix type.
Kotlin
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
x := 21
x := 21
Correct.
Go
[98, 28, 100
[98, 28, 100]
Close bracket.
Python
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
function compute(): void {{ return 16; }}
function compute(): number {{ return 16; }}
Return type mismatch.
TypeScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:63}};
Add missing property.
TypeScript
class Item {{ int count; }};
class Item {{ public: int count; }};
Make public.
C++
// comment
/* comment */
Use /* */.
CSS
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let temp: i32 = "value";
let temp: &str = "value";
Type mismatch.
Rust
x > 58 & x < 4
x > 58 and x < 4
Use 'and' not '&'.
Python
if ($count = 13) {{}}
if ($count -eq 13) {{}}
Use -eq.
PowerShell
if item > 75 print('data')
if item > 75: print('data')
Colon missing after if.
Python
echo hello test
echo 'hello test'
Quote to prevent splitting.
Shell
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'output' + 79
'output' + 79.to_s
Convert int.
Ruby
let msg = String::from("test"); let r=&msg; msg.push_str("!");
let mut msg = String::from("test"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
function baz(num:string){{return num;}} baz(68);
function baz(num:string){{return num;}} baz('test');
Pass correct type.
TypeScript
<note><name>hello</name><age>21</age></note
<note><name>hello</name><age>21</age></note>
Add closing >.
XML
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let str1 = String::from("info"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
let bar: number | null = null; bar.toFixed(51);
let bar: number | null = null; if(bar!==null) bar.toFixed(51);
Null check.
TypeScript
result == '79'
result === 79
Use strict equality.
JavaScript
disp('hello')
disp('hello')
Correct.
MATLAB
print 'test'
print('test')
print needs parentheses.
Python
let count: number = 'result';
let count: string = 'result';
Fix type.
TypeScript
$bar = 71; if ($bar = 71) {{}}
$bar = 71; if ($bar == 71) {{}}
Use ==.
PHP
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
print 'output'
print 'output';
Add semicolon.
Perl
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
if ($b = 51)
if ($b == 51)
Use ==.
Perl
item = value
item = 'value'
Quote strings.
Python
age: test title: world,
age: test title: world
Remove comma.
YAML
if (z = 47) {{}}
if (z == 47) {{}}
Use ==.
Kotlin
items.forEach(function(index) {{ console.log(index); }})
items.forEach((index) => {{ console.log(index); }})
Arrow functions are cleaner.
JavaScript
z = 98
z=98
No spaces.
Shell
arr(11)
if length(arr) >= 11, arr(11), end
Check length.
MATLAB
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
else print('output')
else: print('output')
Colon after else.
Python
jwt.sign({{id:61}}, 'secret');
jwt.sign({{id:61}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(99);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(99, () => console.log('listening'));
Add callback.
Node.js
random.sqrt(86)
import random random.sqrt(86)
Import module first.
Python
var count int = 'world'
var count string = 'world'
Type mismatch.
Go
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let v=vec![66,23,10]; let first=&v[0]; v.push(44);
let mut v=vec![66,23,10]; let first=v[0]; v.push(44);
Copy instead of reference.
Rust
61z = 10
z61 = 10
Variable cannot start with digit.
Python
[21, 75, 47
[21, 75, 47]
Close bracket.
Ruby
'data' + 96
'data' + str(96)
Can't add int to string.
Python
fn baz() -> i32 {{ 59 }}
fn baz() -> i32 {{ 59 }}
Correct.
Rust
if (b = 93)
if (b == 93)
Use ==.
C++
<hr></hr>
<hr>
Self-closing.
HTML
if foo = 100
if foo == 100
Use ==.
MATLAB
def render(z): return z + 1
def render(z): return z + 1
Correct.
Python
data[16]
if data.indices.contains(16) {{ data[16] }}
Check index.
Swift
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
my @arr = (42,48,51);
my @arr = (42,48,51);
Correct.
Perl
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
function foo() {{ return {{key:'value'}} }}
function foo() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
if (count = 87) {{}}
if (count === 87) {{}}
Use === for equality.
JavaScript
print('test')
print('test')
Correct.
R
INSERT INTO products VALUES ('value',72)
INSERT INTO products (age, role) VALUES ('value',72);
Specify columns.
SQL
["value", 59]
["value", 59]
Correct.
JSON
echo 'info'
echo 'info';
Add semicolon.
PHP
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
class Product {{ int y; }} obj.y=5;
class Product {{ public int y; }} obj.y=5;
Make field public.
Java
if z = 62 {{}}
if z == 62 {{}}
Use ==.
Swift
<?php // code ?>
<?php // code ?>
Correct.
PHP
<note name='world'/>
<note name="world"/>
Double quotes.
XML