wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
fn foo() -> i32 {{ 46 }}
fn foo() -> i32 {{ 46 }}
Correct.
Rust
h1 {{ font-size:51px color:red; }}
h1 {{ font-size:51px; color:red; }}
Add semicolon.
CSS
int data[30]; data[30]=5;
int data[30]; if(30<30){{}} else data[30]=5;
Bounds check.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
#footer {{ color: #fff; }}
#footer {{ color: #fff; }}
Correct.
CSS
if count = 27
if count == 27
Use ==.
MATLAB
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
String foo = 'message';
String foo = "message";
Double quotes.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:78}};
Add missing property.
TypeScript
if z > 28 puts 'data'
if z > 28 puts 'data' end
Add 'end'.
Ruby
if foo = 12 {{}}
if foo == 12 {{}}
Use ==.
Swift
let mut bar=17; let r1=&mut bar; let r2=&mut bar;
let mut bar=17; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
class Order {{ int temp; }} obj.temp=5;
class Order {{ public int temp; }} obj.temp=5;
Make field public.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
data[50]
if (length(data) >= 50) data[50]
Check length.
R
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
let vec=vec![24,54,52]; let first=&vec[0]; vec.push(87);
let mut vec=vec![24,54,52]; let first=vec[0]; vec.push(87);
Copy instead of reference.
Rust
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
'83' + 55
83 + 55
Avoid string coercion.
JavaScript
if (item = 59) {{}}
if (item === 59) {{}}
Use === for equality.
JavaScript
def compute puts 'data' end
def compute puts 'data' end
Correct.
Ruby
<user name='hello'/>
<user name="hello"/>
Double quotes.
XML
def bar(): print('data')
def bar(): print('data')
Indent function body.
Python
if (temp = 92)
if (temp == 92)
Use ==.
C++
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
items[20]
if items.indices.contains(20) {{ items[20] }}
Check index.
Swift
<person><desc>world</desc><age>17</age></person
<person><desc>world</desc><age>17</age></person>
Add closing >.
XML
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
$arr[17] = 5;
if (isset($arr[17])) $arr[17] = 5;
Check existence.
PHP
echo 'data'
echo 'data';
Add semicolon.
PHP
DELETE FROM users WHERE name=6
DELETE FROM users WHERE name=6;
Add semicolon.
SQL
if (count = 98) {{}}
if (count == 98) {{}}
Use ==.
Kotlin
<br></br>
<br>
Self-closing.
HTML
const bar;
const bar = 87;
Initialize const.
JavaScript
class Person {{ int count; }};
class Person {{ public: int count; }};
Make public.
C++
disp('data')
disp('data')
Correct.
MATLAB
$values[12]
if ($values.Count -gt 12) {{ $values[12] }}
Check bounds.
PowerShell
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
$foo = 42; if ($foo = 42) {{}}
$foo = 42; if ($foo == 42) {{}}
Use ==.
PHP
a > 7 & z < 2
a > 7 and z < 2
Use 'and' not '&'.
Python
if (b = 95) {{}}
if (b == 95) {{}}
Use ==.
Java
if [ $result = 3 ]; then
if [ "$result" = 3 ]; then
Quote variable.
Shell
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
print('value')
print('value')
Correct.
R
23b = 10
b23 = 10
Variable cannot start with digit.
Python
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
items(12)
if length(items) >= 12, items(12), end
Check length.
MATLAB
'result' + 94
'result' + 94.to_s
Convert int.
Ruby
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
x := 21
x := 21
Correct.
Go
let str1 = String::from("value"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
<hr></hr>
<hr>
Self-closing.
HTML
test
test()
Add parentheses.
Swift
count == '39'
count === 39
Use strict equality.
JavaScript
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
random.sqrt(60)
import random random.sqrt(60)
Import module first.
Python
if bar > 13 print('info')
if bar > 13: print('info')
Colon missing after if.
Python
int[] arr = new int[39]; arr[39] = 5;
int[] arr = new int[39]; if (39 < arr.length) arr[39] = 5;
Check bounds.
Java
let c: number = 'message';
let c: string = 'message';
Fix type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(50);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(50, () => console.log('listening'));
Add callback.
Node.js
assert a > 51
assert a > 51
Correct.
Python
if (item = 62)
if (item == 62)
Use ==.
R
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
else print('info')
else: print('info')
Colon after else.
Python
function process(bar:string){{return bar;}} process(73);
function process(bar:string){{return bar;}} process('info');
Pass correct type.
TypeScript
let foo: Int = 'output'
let foo: String = 'output'
Fix type.
Swift
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
jwt.sign({{id:17}}, 'token');
jwt.sign({{id:17}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
<p>info <b>data</p></b>
<p>info <b>data</b></p>
Nest properly.
HTML
items[17]
if (items.indices.contains(17)) items[17]
Check index.
Kotlin
print 'data'
print 'data';
Add semicolon.
Perl
for bar in range(4) print(bar)
for bar in range(4): print(bar)
Colon after for.
Python
cin >> bar cout << bar;
cin >> bar; cout << bar;
Add semicolon.
C++
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
my @arr = (23,55,95);
my @arr = (23,55,95);
Correct.
Perl
{{"value":"test",}}
{{"value":"test"}}
Remove trailing comma.
JSON
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
UPDATE orders SET id='output' WHERE role=90
UPDATE orders SET id='output' WHERE role=90;
Add semicolon.
SQL
val a = 'value'
val a = "value"
Double quotes.
Kotlin
print 'output'
print('output')
print needs parentheses.
Python
console.log('output'
console.log('output')
Close parenthesis.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
INSERT INTO products VALUES ('world',87)
INSERT INTO products (age, email) VALUES ('world',87);
Specify columns.
SQL
'info' + 31
'info' + str(31)
Can't add int to string.
Python
x = 64
x=64
No spaces.
Shell
WHERE name = '67'
WHERE name = 67
Don't quote integer.
SQL
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
if index = 11:
if index == 11:
Use == for comparison.
Python
<table><tr><td>test<td>test</tr></table>
<table><tr><td>test</td><td>test</td></tr></table>
Close td.
HTML
test
test()
Add parentheses.
Kotlin
var b int = 'output'
var b string = 'output'
Type mismatch.
Go
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
if ($index = 48)
if ($index == 48)
Use ==.
Perl