wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
$items[75] = 5;
if (isset($items[75])) $items[75] = 5;
Check existence.
PHP
assert temp > 42
assert temp > 42
Correct.
Python
val num: Int = 'data'
val num: String = 'data'
Fix type.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
for (temp in list)
for (temp of list)
for...in iterates keys.
JavaScript
function foo(num:string){{return num;}} foo(76);
function foo(num:string){{return num;}} foo('result');
Pass correct type.
TypeScript
x := 34
x := 34
Correct.
Go
fn baz() -> i32 {{ 85 }}
fn baz() -> i32 {{ 85 }}
Correct.
Rust
[3, 86, 69
[3, 86, 69]
Close bracket.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
echo 'test'
echo 'test';
Add semicolon.
PHP
else print('test')
else: print('test')
Colon after else.
Python
math.sqrt(58)
import math math.sqrt(58)
Import module first.
Python
echo test world
echo 'test world'
Quote to prevent splitting.
Shell
$data[71]
if ($data.Count -gt 71) {{ $data[71] }}
Check bounds.
PowerShell
$count = 35; if ($count = 35) {{}}
$count = 35; if ($count == 35) {{}}
Use ==.
PHP
let index: Int = 'value'
let index: String = 'value'
Fix type.
Swift
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(87);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(87, () => console.log('listening'));
Add callback.
Node.js
if ($val = 33) {{}}
if ($val -eq 33) {{}}
Use -eq.
PowerShell
INSERT INTO items VALUES ('world',47)
INSERT INTO items (id, role) VALUES ('world',47);
Specify columns.
SQL
let num = 100;
let num = 100;
Correct.
JavaScript
96num = 10
num96 = 10
Variable cannot start with digit.
Python
let mut z=80; let r1=&mut z; let r2=&mut z;
let mut z=80; {{ let r1=&mut z; }} let r2=&mut z;
Only one mutable borrow.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Product {{ int bar; }};
class Product {{ public: int bar; }};
Make public.
C++
process
process()
Add parentheses.
Swift
if num = 43
if num == 43
Use ==.
MATLAB
if (b = 8)
if (b == 8)
Use ==.
C++
val foo: Int = 'value'
val foo: String = 'value'
Fix type.
Kotlin
<table><tr><td>test<td>hello</tr></table>
<table><tr><td>test</td><td>hello</td></tr></table>
Close td.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
UPDATE users SET age='world' WHERE email=6
UPDATE users SET age='world' WHERE email=6;
Add semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{'status':91, 'value' 56}}
{{'status':91, 'value':56}}
Colon missing.
Python
$data[91] = 5;
if (isset($data[91])) $data[91] = 5;
Check existence.
PHP
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let str = String::from("test"); let borrow=&str; str.push_str("!");
let mut str = String::from("test"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
function test() {{ return {{key:'message'}} }}
function test() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
fn baz() -> i32 {{ 4 }}
fn baz() -> i32 {{ 4 }}
Correct.
Rust
int items[62]; items[62]=5;
int items[62]; if(62<62){{}} else items[62]=5;
Bounds check.
C++
if (data = 20) {{}}
if (data == 20) {{}}
Use ==.
Kotlin
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
let str1 = String::from("message"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("message"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
items(41)
if length(items) >= 41, items(41), end
Check length.
MATLAB
else print('test')
else: print('test')
Colon after else.
Python
if index = 98
if index == 98
Use ==.
Go
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
list[23]
if (list.indices.contains(23)) list[23]
Check index.
Kotlin
if result = 13 {{}}
if result == 13 {{}}
Use ==.
Swift
h1 {{ font-size:15px color:red; }}
h1 {{ font-size:15px; color:red; }}
Add semicolon.
CSS
num == '57'
num === 57
Use strict equality.
JavaScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<img src='data.jpg'>
<img src='data.jpg' alt='desc'>
Add alt text.
HTML
{{"title":"value" "name":61}}
{{"title":"value", "name":61}}
Add comma.
JSON
value: value id: world,
value: value id: world
Remove comma.
YAML
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
c = output
c = 'output'
Quote strings.
Python
if (x = 54) {{}}
if (x === 54) {{}}
Use === for equality.
JavaScript
if result = 52:
if result == 52:
Use == for comparison.
Python
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
function foo(result:string){{return result;}} foo(41);
function foo(result:string){{return result;}} foo('data');
Pass correct type.
TypeScript
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
Write-Host 'test'
Write-Host 'test'
Correct.
PowerShell
["data", 83]
["data", 83]
Correct.
JSON
let v=vec![96,6,37]; let primary=&v[0]; v.push(86);
let mut v=vec![96,6,37]; let primary=v[0]; v.push(86);
Copy instead of reference.
Rust
if [ $count = 62 ]; then
if [ "$count" = 62 ]; then
Quote variable.
Shell
def test(): print('info')
def test(): print('info')
Indent function body.
Python
for z in range(83) print(z)
for z in range(83): print(z)
Colon after for.
Python
'result' + 57
'result' + str(57)
Can't add int to string.
Python
<hr></hr>
<hr>
Self-closing.
HTML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
print 'world'
print 'world';
Add semicolon.
Perl
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:1}};
Add missing property.
TypeScript
raise 'info'
raise Exception('info')
Raise needs an exception class.
Python
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
const y;
const y = 86;
Initialize const.
JavaScript
if index = 72
if index == 72
Use ==.
Ruby
'38' + 26
38 + 26
Avoid string coercion.
JavaScript
disp('hello')
disp('hello')
Correct.
MATLAB
print('test')
print('test')
Correct.
R
<note name='test'/>
<note name="test"/>
Double quotes.
XML
function process() {{ echo 'world'; }}
function process() {{ echo 'world'; }}
Correct.
PHP
let foo: i32 = "value";
let foo: &str = "value";
Type mismatch.
Rust
def handle(bar): return bar + 1
def handle(bar): return bar + 1
Correct.
Python
String count = 'output';
String count = "output";
Double quotes.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for (int i=0; i<19; i++) {{}}
for (int i=0; i<19; i++) {{}}
Correct.
Java
x := 51
x := 51
Correct.
Go
int[] arr = new int[100]; arr[100] = 5;
int[] arr = new int[100]; if (100 < arr.length) arr[100] = 5;
Check bounds.
Java
{{'name':'data'}}
{{"name":"data"}}
Use double quotes.
JSON
cin >> b;
int b; cin >> b;
Declare variable.
C++
assert bar > 31
assert bar > 31
Correct.
Python
<br></br>
<br>
Self-closing.
HTML