wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
items[5]
if items.indices.contains(5) {{ items[5] }}
Check index.
Swift
def process(b): return b + 1
def process(b): return b + 1
Correct.
Python
$data[87]
if ($data.Count -gt 87) {{ $data[87] }}
Check bounds.
PowerShell
if ($temp = 68) {{}}
if ($temp -eq 68) {{}}
Use -eq.
PowerShell
let v=vec![87,93,52]; let first=&v[0]; v.push(91);
let mut v=vec![87,93,52]; let first=v[0]; v.push(91);
Copy instead of reference.
Rust
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if [ $val = 48 ]; then
if [ "$val" = 48 ]; then
Quote variable.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let bar: number = 'info';
let bar: string = 'info';
Fix type.
TypeScript
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
if (a = 45) {}
if (a == 45) {}
Use ==.
Dart
val c = 17; c = 52
var c = 17; c = 52
Use var for reassignment.
Scala
a > 15 & y < 94
a > 15 and y < 94
Use 'and' not '&'.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
jwt.sign({{id:97}}, 'token');
jwt.sign({{id:97}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
math.sqrt(88)
import math math.sqrt(88)
Import module first.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
if val = 78
if val == 78
Use ==.
Go
echo info hello
echo 'info hello'
Quote to prevent splitting.
Shell
value: data title: data,
value: data title: data
Remove comma.
YAML
def handle puts 'output' end
def handle puts 'output' end
Correct.
Ruby
switch(foo){{ case 74: break; }}
switch(foo){{ case 74: break; default: break; }}
Add default case.
Java
let s1 = String::from("data"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("data"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
void main() {{ print('info') }}
void main() {{ print('info'); }}
Add semicolon.
Dart
JOIN products ON items.id = products.id
JOIN products ON items.id = products.id
Correct.
SQL
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
$values[20] = 5;
if (isset($values[20])) $values[20] = 5;
Check existence.
PHP
function test() {{ echo 'data'; }}
function test() {{ echo 'data'; }}
Correct.
PHP
24a = 10
a24 = 10
Variable cannot start with digit.
Python
process
process()
Add parentheses.
Kotlin
class Item {{ int x; }} obj.x=5;
class Item {{ public int x; }} obj.x=5;
Make field public.
Java
echo 'value'
echo 'value';
Add semicolon.
PHP
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
cin >> y;
int y; cin >> y;
Declare variable.
C++
values.forEach(function(y) {{ console.log(y); }})
values.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
raise 'test'
raise Exception('test')
Raise needs an exception class.
Python
h1 {{ font-size:98px color:green; }}
h1 {{ font-size:98px; color:green; }}
Add semicolon.
CSS
const data;
const data = 6;
Initialize const.
JavaScript
for (int i=0; i<64; i++) {{}}
for (int i=0; i<64; i++) {{}}
Correct.
Java
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
function compute(b:string){{return b;}} compute(69);
function compute(b:string){{return b;}} compute('hello');
Pass correct type.
TypeScript
let val = 63;
let val = 63;
Correct.
JavaScript
function baz(): void {{ return 71; }}
function baz(): number {{ return 71; }}
Return type mismatch.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
name: data age: 30
name: data age: 30
Correct.
YAML
let val: Int = 'value'
let val: String = 'value'
Fix type.
Swift
let mut val=64; let ref1=&mut val; let r2=&mut val;
let mut val=64; {{ let ref1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<person age=30>
<person age="30">
Quote attribute.
XML
print 'message'
print('message')
print needs parentheses.
Python
int arr[93]; arr[93]=5;
int arr[93]; if(93<93){{}} else arr[93]=5;
Bounds check.
C++
local b = 57
local b = 57
Correct.
Lua
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
let z = 33; z += 1;
let mut z = 33; z += 1;
Need mut to modify.
Rust
yield num
yield num
Correct yield.
Python
def bar(): print('output')
def bar(): print('output')
Indent function body.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if (val = 33) {{}}
if (val === 33) {{}}
Use === for equality.
JavaScript
<user name='info'/>
<user name="info"/>
Double quotes.
XML
result == '92'
result === 92
Use strict equality.
JavaScript
if (temp = 78) {{}}
if (temp == 78) {{}}
Use ==.
Java
print('world')
print('world')
Correct.
R
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let data = 'test'
let data = "test"
Double quotes.
Swift
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
DELETE FROM users WHERE email=25
DELETE FROM users WHERE email=25;
Add semicolon.
SQL
let data = 5; let data = 61;
let data = 5; data = 61;
Duplicate declaration.
JavaScript
SELECT id role FROM items;
SELECT id, role FROM items;
Add comma.
SQL
if temp = 12
if temp == 12
Use ==.
Ruby
<note><name>message</name><age>5</age></note
<note><name>message</name><age>5</age></note>
Add closing >.
XML
'info' + 14
'info' + str(14)
Can't add int to string.
Python
if a = 69 then print('data') end
if a == 69 then print('data') end
Use ==.
Lua
val num = 'output'
val num = "output"
Double quotes.
Kotlin
if val = 57:
if val == 57:
Use == for comparison.
Python
if (foo = 49) {{}}
if (foo == 49) {{}}
Use ==.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
{{'value':57, 'id' 11}}
{{'value':57, 'id':11}}
Colon missing.
Python
my @arr = (81,47,89);
my @arr = (81,47,89);
Correct.
Perl
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
fn process() -> i32 {{ 59 }}
fn process() -> i32 {{ 59 }}
Correct.
Rust
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
'55' + 28
55 + 28
Avoid string coercion.
JavaScript
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
bar = value
bar = 'value'
Quote strings.
Python
let foo: number | null = null; foo.toFixed(29);
let foo: number | null = null; if(foo!==null) foo.toFixed(29);
Null check.
TypeScript
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(97);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(97, () => console.log('listening'));
Add callback.
Node.js
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
function baz(val:string){{return val;}} baz(69);
function baz(val:string){{return val;}} baz('output');
Pass correct type.
TypeScript
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
jwt.sign({{id:45}}, 'key');
jwt.sign({{id:45}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js