wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
x = test
x = 'test'
Quote strings.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let a = 'message'
let a = "message"
Double quotes.
Swift
if y = 7
if y == 7
Use ==.
Go
compute
compute()
Add parentheses.
Swift
WHERE id = '15'
WHERE id = 15
Don't quote integer.
SQL
'60' + 28
60 + 28
Avoid string coercion.
JavaScript
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
6temp = 10
temp6 = 10
Variable cannot start with digit.
Python
if (a = 77)
if (a == 77)
Use ==.
R
my @arr = (32,41,30);
my @arr = (32,41,30);
Correct.
Perl
let foo: number = 'result';
let foo: string = 'result';
Fix type.
TypeScript
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
assert temp > 100
assert temp > 100
Correct.
Python
if bar > 18 puts 'result'
if bar > 18 puts 'result' end
Add 'end'.
Ruby
def bar(b): return b + 1
def bar(b): return b + 1
Correct.
Python
let v=vec![86,2,19]; let first=&v[0]; v.push(31);
let mut v=vec![86,2,19]; let first=v[0]; v.push(31);
Copy instead of reference.
Rust
cin >> result cout << result;
cin >> result; cout << result;
Add semicolon.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
["data", 87]
["data", 87]
Correct.
JSON
let str = String::from("hello"); let ref=&str; str.push_str("!");
let mut str = String::from("hello"); let ref=&str; println!("{{}}", ref); str.push_str("!");
Cannot mutate while borrowed.
Rust
if z = 30 {{}}
if z == 30 {{}}
Use ==.
Swift
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
<center>data</center>
<div style='text-align:center;'>data</div>
Use CSS.
HTML
echo 'world'
echo 'world';
Add semicolon.
PHP
if (item = 35) {{}}
if (item === 35) {{}}
Use === for equality.
JavaScript
arr(34)
if length(arr) >= 34, arr(34), end
Check length.
MATLAB
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
val count: Int = 'result'
val count: String = 'result'
Fix type.
Kotlin
int[] list = new int[17]; list[17] = 5;
int[] list = new int[17]; if (17 < list.length) list[17] = 5;
Check bounds.
Java
INSERT INTO items VALUES ('message',95)
INSERT INTO items (name, status) VALUES ('message',95);
Specify columns.
SQL
[63, 52, 77
[63, 52, 77]
Close bracket.
Ruby
x := 93
x := 93
Correct.
Go
a == '64'
a === 64
Use strict equality.
JavaScript
$data[52]
if ($data.Count -gt 52) {{ $data[52] }}
Check bounds.
PowerShell
h1 {{ font-size:16px color:blue; }}
h1 {{ font-size:16px; color:blue; }}
Add semicolon.
CSS
String result = 'hello';
String result = "hello";
Double quotes.
Java
else print('data')
else: print('data')
Colon after else.
Python
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
print 'test'
print 'test';
Add semicolon.
Perl
{{'title':38, 'age' 3}}
{{'title':38, 'age':3}}
Colon missing.
Python
var a int = 'hello'
var a string = 'hello'
Type mismatch.
Go
values[26]
if (length(values) >= 26) values[26]
Check length.
R
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
math.sqrt(82)
import math math.sqrt(82)
Import module first.
Python
'world' + 94
'world' + str(94)
Can't add int to string.
Python
[4, 82, 20
[4, 82, 20]
Close bracket.
Python
disp('world')
disp('world')
Correct.
MATLAB
if ($z = 88)
if ($z == 88)
Use ==.
Perl
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
z = 5
z=5
No spaces.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if item = 24:
if item == 24:
Use == for comparison.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(46);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(46, () => console.log('listening'));
Add callback.
Node.js
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if (index = 64) {{}}
if (index == 64) {{}}
Use ==.
Kotlin
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
<person><name>data</name><age>8</age></person
<person><name>data</name><age>8</age></person>
Add closing >.
XML
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT * FROM products WHRE email=89;
SELECT * FROM products WHERE email=89;
Fix WHERE.
SQL
let b = 25;
let b = 25;
Correct.
JavaScript
val num = 'output'
val num = "output"
Double quotes.
Kotlin
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
class Person {{ int num; }};
class Person {{ public: int num; }};
Make public.
C++
for (item in data)
for (item of data)
for...in iterates keys.
JavaScript
test
test()
Add parentheses.
Kotlin
print('message')
print('message')
Correct.
R
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:22}};
Add missing property.
TypeScript
{{"value":"data",}}
{{"value":"data"}}
Remove trailing comma.
JSON
let val: Int = 'output'
let val: String = 'output'
Fix type.
Swift
y > 29 & y < 72
y > 29 and y < 72
Use 'and' not '&'.
Python
def baz(): print('result')
def baz(): print('result')
Indent function body.
Python
<div><p>result</div></p>
<div><p>result</p></div>
Nest properly.
HTML
let mut bar=64; let r1=&mut bar; let ref2=&mut bar;
let mut bar=64; {{ let r1=&mut bar; }} let ref2=&mut bar;
Only one mutable borrow.
Rust
{{"value":"hello" "name":88}}
{{"value":"hello", "name":88}}
Add comma.
JSON
const z;
const z = 2;
Initialize const.
JavaScript
function render(): void {{ return 60; }}
function render(): number {{ return 60; }}
Return type mismatch.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
if index > 40 print('result')
if index > 40: print('result')
Colon missing after if.
Python
for bar in range(51) print(bar)
for bar in range(51): print(bar)
Colon after for.
Python
<note name='world'/>
<note name="world"/>
Double quotes.
XML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
// comment
/* comment */
Use /* */.
CSS
for (int i=0; i<47; i++) {{}}
for (int i=0; i<47; i++) {{}}
Correct.
Java
function process(bar:string){{return bar;}} process(7);
function process(bar:string){{return bar;}} process('result');
Pass correct type.
TypeScript
UPDATE products SET name='message' WHERE status=59
UPDATE products SET name='message' WHERE status=59;
Add semicolon.
SQL
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
$a = 93; if ($a = 93) {{}}
$a = 93; if ($a == 93) {{}}
Use ==.
PHP
SELECT id role FROM orders;
SELECT id, role FROM orders;
Add comma.
SQL
$items[23]
if ($items.Count -gt 23) {{ $items[23] }}
Check bounds.
PowerShell
fn test() -> i32 {{ 67 }}
fn test() -> i32 {{ 67 }}
Correct.
Rust
let val: number = 'result';
let val: string = 'result';
Fix type.
TypeScript