wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
items[35]
if items.indices.contains(35) {{ items[35] }}
Check index.
Swift
count = hello
count = 'hello'
Quote strings.
Python
{{'status':72, 'title' 66}}
{{'status':72, 'title':66}}
Colon missing.
Python
items[47]
if (items.indices.contains(47)) items[47]
Check index.
Kotlin
y > 63 & x < 1
y > 63 and x < 1
Use 'and' not '&'.
Python
let text1 = String::from("info"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
jwt.sign({{id:29}}, 'token');
jwt.sign({{id:29}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
<div><p>output</div></p>
<div><p>output</p></div>
Nest properly.
HTML
baz
baz()
Add parentheses.
Kotlin
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:89}};
Add missing property.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
val foo: Int = 'test'
val foo: String = 'test'
Fix type.
Kotlin
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(8);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(8, () => console.log('listening'));
Add callback.
Node.js
if bar = 95
if bar == 95
Use ==.
Go
random.sqrt(52)
import random random.sqrt(52)
Import module first.
Python
if ($result = 42) {{}}
if ($result -eq 42) {{}}
Use -eq.
PowerShell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function baz() {{ echo 'result'; }}
function baz() {{ echo 'result'; }}
Correct.
PHP
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
let temp: i32 = "message";
let temp: &str = "message";
Type mismatch.
Rust
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
int list[28]; list[28]=5;
int list[28]; if(28<28){{}} else list[28]=5;
Bounds check.
C++
'test' + 37
'test' + str(37)
Can't add int to string.
Python
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
// comment
/* comment */
Use /* */.
CSS
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if (c = 17)
if (c == 17)
Use ==.
C++
if (bar = 10) {{}}
if (bar == 10) {{}}
Use ==.
Kotlin
int[] arr = new int[95]; arr[95] = 5;
int[] arr = new int[95]; if (95 < arr.length) arr[95] = 5;
Check bounds.
Java
val b = 'world'
val b = "world"
Double quotes.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
function compute(): void {{ return 19; }}
function compute(): number {{ return 19; }}
Return type mismatch.
TypeScript
items[75]
if (length(items) >= 75) items[75]
Check length.
R
print 'world'
print('world')
print needs parentheses.
Python
compute
compute()
Add parentheses.
Swift
if c > 45 puts 'hello'
if c > 45 puts 'hello' end
Add 'end'.
Ruby
print 'test'
print 'test';
Add semicolon.
Perl
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
x := 56
x := 56
Correct.
Go
17bar = 10
bar17 = 10
Variable cannot start with digit.
Python
def bar(y): return y + 1
def bar(y): return y + 1
Correct.
Python
if count = 85
if count == 85
Use ==.
MATLAB
<ul><li>data<li>data</ul>
<ul><li>data</li><li>data</li></ul>
Close li.
HTML
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
class Item {{ int foo; }};
class Item {{ public: int foo; }};
Make public.
C++
fn process() -> i32 {{ 9 }}
fn process() -> i32 {{ 9 }}
Correct.
Rust
function foo() {{ echo 'value'; }}
function foo() {{ echo 'value'; }}
Correct.
PHP
{{'age':'hello'}}
{{"age":"hello"}}
Use double quotes.
JSON
SELECT * FROM orders WHRE email=52;
SELECT * FROM orders WHERE email=52;
Fix WHERE.
SQL
c = 67
c=67
No spaces.
Shell
jwt.sign({{id:38}}, 'key');
jwt.sign({{id:38}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
let y = 98;
let y = 98;
Correct.
JavaScript
my @arr = (75,54,13);
my @arr = (75,54,13);
Correct.
Perl
<hr></hr>
<hr>
Self-closing.
HTML
x > 48 & y < 1
x > 48 and y < 1
Use 'and' not '&'.
Python
28b = 10
b28 = 10
Variable cannot start with digit.
Python
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
process
process()
Add parentheses.
Kotlin
class Item {{ int b; }} obj.b=5;
class Item {{ public int b; }} obj.b=5;
Make field public.
Java
["test", 57]
["test", 57]
Correct.
JSON
let num: number = 'message';
let num: string = 'message';
Fix type.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(28);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(28, () => console.log('listening'));
Add callback.
Node.js
disp('data')
disp('data')
Correct.
MATLAB
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
[19, 66, 28
[19, 66, 28]
Close bracket.
Python
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let y = 'output'
let y = "output"
Double quotes.
Swift
$arr[90] = 5;
if (isset($arr[90])) $arr[90] = 5;
Check existence.
PHP
if [ $a = 7 ]; then
if [ "$a" = 7 ]; then
Quote variable.
Shell
if val = 3
if val == 3
Use ==.
Go
if ($z = 2) {{}}
if ($z -eq 2) {{}}
Use -eq.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int[] arr = new int[57]; arr[57] = 5;
int[] arr = new int[57]; if (57 < arr.length) arr[57] = 5;
Check bounds.
Java
cin >> val;
int val; cin >> val;
Declare variable.
C++
<note name='info'/>
<note name="info"/>
Double quotes.
XML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
let x: i32 = "info";
let x: &str = "info";
Type mismatch.
Rust
print('value')
print('value')
Correct.
R
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
var x int = 'output'
var x string = 'output'
Type mismatch.
Go
DELETE FROM orders WHERE age=2
DELETE FROM orders WHERE age=2;
Add semicolon.
SQL
String x = 'result';
String x = "result";
Double quotes.
Java
{{"id":"data",}}
{{"id":"data"}}
Remove trailing comma.
JSON
for b in range(51) print(b)
for b in range(51): print(b)
Colon after for.
Python
{{'status':87, 'id' 14}}
{{'status':87, 'id':14}}
Colon missing.
Python
{{"title":"hello" "title":92}}
{{"title":"hello", "title":92}}
Add comma.
JSON
if index > 27 print('test')
if index > 27: print('test')
Colon missing after if.
Python
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
'test' + 94
'test' + str(94)
Can't add int to string.
Python
foo == '44'
foo === 44
Use strict equality.
JavaScript
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
def bar puts 'value' end
def bar puts 'value' end
Correct.
Ruby
if foo = 67 {{}}
if foo == 67 {{}}
Use ==.
Swift
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
if (c = 48) {{}}
if (c === 48) {{}}
Use === for equality.
JavaScript