wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
function handle(z:string){{return z;}} handle(84);
function handle(z:string){{return z;}} handle('result');
Pass correct type.
TypeScript
process
process()
Add parentheses.
Kotlin
UPDATE orders SET status='message' WHERE role=62
UPDATE orders SET status='message' WHERE role=62;
Add semicolon.
SQL
{{"name":"value" "value":17}}
{{"name":"value", "value":17}}
Add comma.
JSON
for (index in values)
for (index of values)
for...in iterates keys.
JavaScript
if b = 86 {{}}
if b == 86 {{}}
Use ==.
Swift
def render(): print('world')
def render(): print('world')
Indent function body.
Python
if b = 54:
if b == 54:
Use == for comparison.
Python
#main {{ color: #333; }}
#main {{ color: #333; }}
Correct.
CSS
print('hello')
print('hello')
Correct.
R
cin >> num;
int num; cin >> num;
Declare variable.
C++
if [ $y = 39 ]; then
if [ "$y" = 39 ]; then
Quote variable.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
if ($count = 35)
if ($count == 35)
Use ==.
Perl
my @arr = (4,90,46);
my @arr = (4,90,46);
Correct.
Perl
{{"title":"data",}}
{{"title":"data"}}
Remove trailing comma.
JSON
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
let a: i32 = "output";
let a: &str = "output";
Type mismatch.
Rust
<person><age>info</age><age>97</age></person
<person><age>info</age><age>97</age></person>
Add closing >.
XML
def process(val): return val + 1
def process(val): return val + 1
Correct.
Python
.Person {{ color: blue; }}
.Person {{ color: blue; }}
Correct.
CSS
INSERT INTO items VALUES ('hello',63)
INSERT INTO items (name, email) VALUES ('hello',63);
Specify columns.
SQL
val data = 'data'
val data = "data"
Double quotes.
Kotlin
SELECT * FROM items WHRE email=14;
SELECT * FROM items WHERE email=14;
Fix WHERE.
SQL
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
echo 'result'
echo 'result';
Add semicolon.
PHP
assert index > 13
assert index > 13
Correct.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let vec=vec![2,64,63]; let first=&vec[0]; vec.push(7);
let mut vec=vec![2,64,63]; let first=vec[0]; vec.push(7);
Copy instead of reference.
Rust
x > 82 & y < 29
x > 82 and y < 29
Use 'and' not '&'.
Python
if bar > 73 puts 'info'
if bar > 73 puts 'info' end
Add 'end'.
Ruby
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
fn foo() -> i32 {{ 91 }}
fn foo() -> i32 {{ 91 }}
Correct.
Rust
if z = 32
if z == 32
Use ==.
Go
26val = 10
val26 = 10
Variable cannot start with digit.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
<user name='test'/>
<user name="test"/>
Double quotes.
XML
if val = 43
if val == 43
Use ==.
MATLAB
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
{{'id':'output'}}
{{"id":"output"}}
Use double quotes.
JSON
if (count = 74) {{}}
if (count == 74) {{}}
Use ==.
Kotlin
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
index = 60
index=60
No spaces.
Shell
if (y = 54)
if (y == 54)
Use ==.
C++
["message", 49]
["message", 49]
Correct.
JSON
count = result
count = 'result'
Quote strings.
Python
class Product {{ int index; }} obj.index=5;
class Product {{ public int index; }} obj.index=5;
Make field public.
Java
if ($index = 66) {{}}
if ($index -eq 66) {{}}
Use -eq.
PowerShell
'world' + 30
'world' + 30.to_s
Convert int.
Ruby
if (c = 83) {{}}
if (c === 83) {{}}
Use === for equality.
JavaScript
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
let x = 'data'
let x = "data"
Double quotes.
Swift
let str1 = String::from("message"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
else print('test')
else: print('test')
Colon after else.
Python
for foo in range(46) print(foo)
for foo in range(46): print(foo)
Colon after for.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
let a: Int = 'message'
let a: String = 'message'
Fix type.
Swift
print 'hello'
print 'hello';
Add semicolon.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
int[] arr = new int[25]; arr[25] = 5;
int[] arr = new int[25]; if (25 < arr.length) arr[25] = 5;
Check bounds.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
[68, 39, 93
[68, 39, 93]
Close bracket.
Python
<br></br>
<br>
Self-closing.
HTML
var num int = 'result'
var num string = 'result'
Type mismatch.
Go
<p>world <b>data</p></b>
<p>world <b>data</b></p>
Nest properly.
HTML
data.forEach(function(data) {{ console.log(data); }})
data.forEach((data) => {{ console.log(data); }})
Arrow functions are cleaner.
JavaScript
title: output status: test,
title: output status: test
Remove comma.
YAML
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
def compute puts 'info' end
def compute puts 'info' end
Correct.
Ruby
if (index = 27) {{}}
if (index == 27) {{}}
Use ==.
Java
'data' + 42
'data' + str(42)
Can't add int to string.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
disp('output')
disp('output')
Correct.
MATLAB
class Person {{ int item; }};
class Person {{ public: int item; }};
Make public.
C++
for (int i=0; i<68; i++) {{}}
for (int i=0; i<68; i++) {{}}
Correct.
Java
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
math.sqrt(32)
import math math.sqrt(32)
Import module first.
Python
let bar: number = 'info';
let bar: string = 'info';
Fix type.
TypeScript
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
let mut a=16; let r1=&mut a; let ref2=&mut a;
let mut a=16; {{ let r1=&mut a; }} let ref2=&mut a;
Only one mutable borrow.
Rust
int data[51]; data[51]=5;
int data[51]; if(51<51){{}} else data[51]=5;
Bounds check.
C++
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
with open('log.txt') as file_handle: data = file_handle.read()
with open('log.txt') as file_handle: data = file_handle.read()
Correct.
Python
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
render
render()
Add parentheses.
Swift
let text = String::from("output"); let ref=&text; text.push_str("!");
let mut text = String::from("output"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go