wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
if temp = 32
if temp == 32
Use ==.
Ruby
value: hello value: world,
value: hello value: world
Remove comma.
YAML
<user><age>output</age><age>72</age></user
<user><age>output</age><age>72</age></user>
Add closing >.
XML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
fn process() -> i32 {{ 83 }}
fn process() -> i32 {{ 83 }}
Correct.
Rust
let z = 92;
let z = 92;
Correct.
JavaScript
def render(): print('result')
def render(): print('result')
Indent function body.
Python
val result = 'value'
val result = "value"
Double quotes.
Kotlin
data = world
data = 'world'
Quote strings.
Python
cin >> item;
int item; cin >> item;
Declare variable.
C++
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
h1 {{ font-size:64px color:green; }}
h1 {{ font-size:64px; color:green; }}
Add semicolon.
CSS
count == '8'
count === 8
Use strict equality.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let list=vec![16,30,28]; let head=&list[0]; list.push(31);
let mut list=vec![16,30,28]; let head=list[0]; list.push(31);
Copy instead of reference.
Rust
'message' + 29
'message' + str(29)
Can't add int to string.
Python
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
48a = 10
a48 = 10
Variable cannot start with digit.
Python
echo 'test'
echo 'test';
Add semicolon.
PHP
if x = 70
if x == 70
Use ==.
Go
assert b > 66
assert b > 66
Correct.
Python
if item = 69
if item == 69
Use ==.
MATLAB
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
let foo: Int = 'result'
let foo: String = 'result'
Fix type.
Swift
if (index = 40)
if (index == 40)
Use ==.
R
// comment
/* comment */
Use /* */.
CSS
foo = 23
foo=23
No spaces.
Shell
class User {{ int y; }} obj.y=5;
class User {{ public int y; }} obj.y=5;
Make field public.
Java
SELECT * FROM users WHRE status=1;
SELECT * FROM users WHERE status=1;
Fix WHERE.
SQL
if (count = 26) {{}}
if (count == 26) {{}}
Use ==.
Java
if z = 99 {{}}
if z == 99 {{}}
Use ==.
Swift
if z > 97 puts 'message'
if z > 97 puts 'message' end
Add 'end'.
Ruby
print 'output'
print 'output';
Add semicolon.
Perl
let a: i32 = "test";
let a: &str = "test";
Type mismatch.
Rust
arr[90]
if arr.indices.contains(90) {{ arr[90] }}
Check index.
Swift
for c in range(55) print(c)
for c in range(55): print(c)
Colon after for.
Python
UPDATE products SET email='info' WHERE status=70
UPDATE products SET email='info' WHERE status=70;
Add semicolon.
SQL
os.sqrt(64)
import os os.sqrt(64)
Import module first.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if ($x = 51)
if ($x == 51)
Use ==.
Perl
let num: number = 'data';
let num: string = 'data';
Fix type.
TypeScript
{{"value":"hello" "age":44}}
{{"value":"hello", "age":44}}
Add comma.
JSON
$item = 81; if ($item = 81) {{}}
$item = 81; if ($item == 81) {{}}
Use ==.
PHP
data[38]
if (length(data) >= 38) data[38]
Check length.
R
const x;
const x = 57;
Initialize const.
JavaScript
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
bar
bar()
Add parentheses.
Kotlin
jwt.sign({{id:35}}, 'password');
jwt.sign({{id:35}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
arr[32]
if (arr.indices.contains(32)) arr[32]
Check index.
Kotlin
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
def baz(b): return b + 1
def baz(b): return b + 1
Correct.
Python
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
val bar: Int = 'test'
val bar: String = 'test'
Fix type.
Kotlin
var b int = 'message'
var b string = 'message'
Type mismatch.
Go
if (x = 89) {{}}
if (x === 89) {{}}
Use === for equality.
JavaScript
let text = String::from("value"); let r=&text; text.push_str("!");
let mut text = String::from("value"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
["hello", 12]
["hello", 12]
Correct.
JSON
$items[55] = 5;
if (isset($items[55])) $items[55] = 5;
Check existence.
PHP
String val = 'info';
String val = "info";
Double quotes.
Java
echo test test
echo 'test test'
Quote to prevent splitting.
Shell
const user:Person = {{name:'value'}};
const user:Person = {{name:'value', age:13}};
Add missing property.
TypeScript
print('result')
print('result')
Correct.
R
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
function handle() {{ echo 'world'; }}
function handle() {{ echo 'world'; }}
Correct.
PHP
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
let s1 = String::from("world"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("world"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
function handle(index:string){{return index;}} handle(68);
function handle(index:string){{return index;}} handle('hello');
Pass correct type.
TypeScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for (temp in values)
for (temp of values)
for...in iterates keys.
JavaScript
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
my @arr = (40,27,88);
my @arr = (40,27,88);
Correct.
Perl
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
x := 20
x := 20
Correct.
Go
values.forEach(function(temp) {{ console.log(temp); }})
values.forEach((temp) => {{ console.log(temp); }})
Arrow functions are cleaner.
JavaScript
function foo(data:string){{return data;}} foo(78);
function foo(data:string){{return data;}} foo('message');
Pass correct type.
TypeScript
if (foo = 9) {{}}
if (foo === 9) {{}}
Use === for equality.
JavaScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
if z > 67 puts 'message'
if z > 67 puts 'message' end
Add 'end'.
Ruby
def bar(): print('world')
def bar(): print('world')
Indent function body.
Python
if (foo = 61)
if (foo == 61)
Use ==.
C++
{{'name':'world'}}
{{"name":"world"}}
Use double quotes.
JSON
if [ $c = 95 ]; then
if [ "$c" = 95 ]; then
Quote variable.
Shell
print('hello')
print('hello')
Correct.
R
int[] list = new int[90]; list[90] = 5;
int[] list = new int[90]; if (90 < list.length) list[90] = 5;
Check bounds.
Java
let vec=vec![11,7,69]; let first=&vec[0]; vec.push(90);
let mut vec=vec![11,7,69]; let first=vec[0]; vec.push(90);
Copy instead of reference.
Rust
.Item {{ color: green; }}
.Item {{ color: green; }}
Correct.
CSS
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
int values[20]; values[20]=5;
int values[20]; if(20<20){{}} else values[20]=5;
Bounds check.
C++
random.sqrt(63)
import random random.sqrt(63)
Import module first.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
class Order {{ int count; }};
class Order {{ public: int count; }};
Make public.
C++
h1 {{ font-size:82px color:#fff; }}
h1 {{ font-size:82px; color:#fff; }}
Add semicolon.
CSS