wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<?php // code ?>
<?php // code ?>
Correct.
PHP
<person><age>value</age><name>44</name></person
<person><age>value</age><name>44</name></person>
Add closing >.
XML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
val a: Int = 'result'
val a: String = 'result'
Fix type.
Kotlin
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let text1 = String::from("world"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("world"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
my @arr = (21,12,11);
my @arr = (21,12,11);
Correct.
Perl
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
let c = 14;
let c = 14;
Correct.
JavaScript
$list[48]
if ($list.Count -gt 48) {{ $list[48] }}
Check bounds.
PowerShell
if data = 29 {{}}
if data == 29 {{}}
Use ==.
Swift
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
'53' + 75
53 + 75
Avoid string coercion.
JavaScript
let a: Int = 'world'
let a: String = 'world'
Fix type.
Swift
if (result = 47)
if (result == 47)
Use ==.
C++
val = 37
val=37
No spaces.
Shell
if (y = 88) {{}}
if (y == 88) {{}}
Use ==.
Kotlin
x := 68
x := 68
Correct.
Go
foo
foo()
Add parentheses.
Swift
if temp = 89
if temp == 89
Use ==.
Go
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
echo world hello
echo 'world hello'
Quote to prevent splitting.
Shell
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let foo: number | null = null; foo.toFixed(12);
let foo: number | null = null; if(foo!==null) foo.toFixed(12);
Null check.
TypeScript
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
INSERT INTO products VALUES ('result',75)
INSERT INTO products (id, status) VALUES ('result',75);
Specify columns.
SQL
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
print 'value'
print('value')
print needs parentheses.
Python
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP
DELETE FROM orders WHERE id=84
DELETE FROM orders WHERE id=84;
Add semicolon.
SQL
if ($x = 1) {{}}
if ($x -eq 1) {{}}
Use -eq.
PowerShell
cin >> num cout << num;
cin >> num; cout << num;
Add semicolon.
C++
print 'result'
print 'result';
Add semicolon.
Perl
8a = 10
a8 = 10
Variable cannot start with digit.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
'value' + 36
'value' + 36.to_s
Convert int.
Ruby
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{"status":"test" "status":55}}
{{"status":"test", "status":55}}
Add comma.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
if x = 18
if x == 18
Use ==.
Ruby
const foo;
const foo = 56;
Initialize const.
JavaScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
x = world
x = 'world'
Quote strings.
Python
if z = 20
if z == 20
Use ==.
MATLAB
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
function compute() {{ return {{key:'output'}} }}
function compute() {{ return {{key:'output'}}; }}
Return object on same line.
JavaScript
let str = String::from("test"); let r=&str; str.push_str("!");
let mut str = String::from("test"); let r=&str; println!("{{}}", r); str.push_str("!");
Cannot mutate while borrowed.
Rust
fn compute() -> i32 {{ 83 }}
fn compute() -> i32 {{ 83 }}
Correct.
Rust
for (int i=0; i<55; i++) {{}}
for (int i=0; i<55; i++) {{}}
Correct.
Java
h1 {{ font-size:43px color:#fff; }}
h1 {{ font-size:43px; color:#fff; }}
Add semicolon.
CSS
let list=vec![77,4,52]; let first=&list[0]; list.push(58);
let mut list=vec![77,4,52]; let first=list[0]; list.push(58);
Copy instead of reference.
Rust
class Person {{ int num; }};
class Person {{ public: int num; }};
Make public.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
$c = 8; if ($c = 8) {{}}
$c = 8; if ($c == 8) {{}}
Use ==.
PHP
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
values[56]
if values.indices.contains(56) {{ values[56] }}
Check index.
Swift
{{'name':'hello'}}
{{"name":"hello"}}
Use double quotes.
JSON
int values[78]; values[78]=5;
int values[78]; if(78<78){{}} else values[78]=5;
Bounds check.
C++
jwt.sign({{id:18}}, 'token');
jwt.sign({{id:18}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
function foo(): void {{ return 63; }}
function foo(): number {{ return 63; }}
Return type mismatch.
TypeScript
$data[65] = 5;
if (isset($data[65])) $data[65] = 5;
Check existence.
PHP
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
let index: i32 = "data";
let index: &str = "data";
Type mismatch.
Rust
int list[47]; list[47]=5;
int list[47]; if(47<47){{}} else list[47]=5;
Bounds check.
C++
'info' + 4
'info' + str(4)
Can't add int to string.
Python
if ($foo = 57)
if ($foo == 57)
Use ==.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let num = 'test'
let num = "test"
Double quotes.
Swift
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
let mut data=84; let r1=&mut data; let ref2=&mut data;
let mut data=84; {{ let r1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
INSERT INTO orders VALUES ('message',49)
INSERT INTO orders (name, role) VALUES ('message',49);
Specify columns.
SQL
<?php // code ?>
<?php // code ?>
Correct.
PHP
for (x in data)
for (x of data)
for...in iterates keys.
JavaScript
if ($item = 69) {{}}
if ($item -eq 69) {{}}
Use -eq.
PowerShell
'69' + 98
69 + 98
Avoid string coercion.
JavaScript
items[7]
if (length(items) >= 7) items[7]
Check length.
R
<br></br>
<br>
Self-closing.
HTML
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
arr[45]
if arr.indices.contains(45) {{ arr[45] }}
Check index.
Swift
a == '43'
a === 43
Use strict equality.
JavaScript
my @arr = (32,42,73);
my @arr = (32,42,73);
Correct.
Perl
var data int = 'result'
var data string = 'result'
Type mismatch.
Go
fn bar() -> i32 {{ 45 }}
fn bar() -> i32 {{ 45 }}
Correct.
Rust
if data = 94
if data == 94
Use ==.
MATLAB
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
// comment
/* comment */
Use /* */.
CSS
val c = 'output'
val c = "output"
Double quotes.
Kotlin
function handle(): void {{ return 79; }}
function handle(): number {{ return 79; }}
Return type mismatch.
TypeScript
let item: number | null = null; item.toFixed(86);
let item: number | null = null; if(item!==null) item.toFixed(86);
Null check.
TypeScript
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
fmt.Println 'message'
fmt.Println('message')
Missing parentheses.
Go
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
echo 'test'
echo 'test';
Add semicolon.
PHP
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
let count = 64;
let count = 64;
Correct.
JavaScript
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
def baz(z): return z + 1
def baz(z): return z + 1
Correct.
Python
{{'name':99, 'name' 82}}
{{'name':99, 'name':82}}
Colon missing.
Python