wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
int[] data = new int[74]; data[74] = 5;
int[] data = new int[74]; if (74 < data.length) data[74] = 5;
Check bounds.
Java
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
list[68]
if (list.indices.contains(68)) list[68]
Check index.
Kotlin
let y: number = 'data';
let y: string = 'data';
Fix type.
TypeScript
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<hr></hr>
<hr>
Self-closing.
HTML
jwt.sign({{id:67}}, 'key');
jwt.sign({{id:67}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
function foo() {{ return {{key:'test'}} }}
function foo() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
console.log('info'
console.log('info')
Close parenthesis.
JavaScript
<center>message</center>
<div style='text-align:center;'>message</div>
Use CSS.
HTML
if temp = 97 {{}}
if temp == 97 {{}}
Use ==.
Swift
if result = 77
if result == 77
Use ==.
Go
if [ $data = 95 ]; then
if [ "$data" = 95 ]; then
Quote variable.
Shell
a > 48 & y < 7
a > 48 and y < 7
Use 'and' not '&'.
Python
bar = output
bar = 'output'
Quote strings.
Python
val a = 'world'
val a = "world"
Double quotes.
Kotlin
<person name='message'/>
<person name="message"/>
Double quotes.
XML
h1 {{ font-size:59px color:#333; }}
h1 {{ font-size:59px; color:#333; }}
Add semicolon.
CSS
print('world')
print('world')
Correct.
R
render
render()
Add parentheses.
Swift
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
let val = 'test'
let val = "test"
Double quotes.
Swift
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
let mut result=93; let ref1=&mut result; let ref2=&mut result;
let mut result=93; {{ let ref1=&mut result; }} let ref2=&mut result;
Only one mutable borrow.
Rust
data[68]
if data.indices.contains(68) {{ data[68] }}
Check index.
Swift
bar
bar()
Add parentheses.
Kotlin
if ($val = 39)
if ($val == 39)
Use ==.
Perl
{{'value':59, 'name' 87}}
{{'value':59, 'name':87}}
Colon missing.
Python
for temp in range(70) print(temp)
for temp in range(70): print(temp)
Colon after for.
Python
'test' + 67
'test' + str(67)
Can't add int to string.
Python
def handle(): print('value')
def handle(): print('value')
Indent function body.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let x = 53;
let x = 53;
Correct.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
String result = 'test';
String result = "test";
Double quotes.
Java
<person><name>test</name><age>45</age></person
<person><name>test</name><age>45</age></person>
Add closing >.
XML
{{"id":"test" "value":95}}
{{"id":"test", "value":95}}
Add comma.
JSON
void test(); int main(){{test();}}
void test(); // prototype int main(){{test();}}
Declare before use.
C++
["world", 51]
["world", 51]
Correct.
JSON
val num: Int = 'result'
val num: String = 'result'
Fix type.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(58);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(58, () => console.log('listening'));
Add callback.
Node.js
echo 'info'
echo 'info';
Add semicolon.
PHP
for (int i=0; i<69; i++) {{}}
for (int i=0; i<69; i++) {{}}
Correct.
Java
var temp int = 'message'
var temp string = 'message'
Type mismatch.
Go
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
x := 50
x := 50
Correct.
Go
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let text = String::from("world"); let ref=&text; text.push_str("!");
let mut text = String::from("world"); let ref=&text; println!("{{}}", ref); text.push_str("!");
Cannot mutate while borrowed.
Rust
else print('hello')
else: print('hello')
Colon after else.
Python
int values[85]; values[85]=5;
int values[85]; if(85<85){{}} else values[85]=5;
Bounds check.
C++
disp('hello')
disp('hello')
Correct.
MATLAB
def foo puts 'info' end
def foo puts 'info' end
Correct.
Ruby
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
let a: i32 = "world";
let a: &str = "world";
Type mismatch.
Rust
if (num = 29) {{}}
if (num == 29) {{}}
Use ==.
Java
function render(num:string){{return num;}} render(23);
function render(num:string){{return num;}} render('info');
Pass correct type.
TypeScript
bar == '6'
bar === 6
Use strict equality.
JavaScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
{{"status":"info",}}
{{"status":"info"}}
Remove trailing comma.
JSON
if index = 99
if index == 99
Use ==.
MATLAB
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
cin >> c;
int c; cin >> c;
Declare variable.
C++
<ul><li>hello<li>hello</ul>
<ul><li>hello</li><li>hello</li></ul>
Close li.
HTML
if (data = 35) {{}}
if (data === 35) {{}}
Use === for equality.
JavaScript
if (a = 24)
if (a == 24)
Use ==.
C++
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
$items[48] = 5;
if (isset($items[48])) $items[48] = 5;
Check existence.
PHP
$a = 61; if ($a = 61) {{}}
$a = 61; if ($a == 61) {{}}
Use ==.
PHP
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
if item > 1 print('info')
if item > 1: print('info')
Colon missing after if.
Python
let item: number | null = null; item.toFixed(46);
let item: number | null = null; if(item!==null) item.toFixed(46);
Null check.
TypeScript
[59, 23, 47
[59, 23, 47]
Close bracket.
Ruby
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (num = 73) {{}}
if (num == 73) {{}}
Use ==.
Kotlin
<br></br>
<br>
Self-closing.
HTML
[98, 72, 10
[98, 72, 10]
Close bracket.
Python
fn baz() -> i32 {{ 64 }}
fn baz() -> i32 {{ 64 }}
Correct.
Rust
DELETE FROM items WHERE name=73
DELETE FROM items WHERE name=73;
Add semicolon.
SQL
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:24}};
Add missing property.
TypeScript
{{'status':'test'}}
{{"status":"test"}}
Use double quotes.
JSON
if result = 5
if result == 5
Use ==.
Ruby
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
status: test status: data,
status: test status: data
Remove comma.
YAML
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
if val = 79
if val == 79
Use ==.
Ruby
if [ $data = 86 ]; then
if [ "$data" = 86 ]; then
Quote variable.
Shell
disp('hello')
disp('hello')
Correct.
MATLAB
<p>info <b>test</p></b>
<p>info <b>test</b></p>
Nest properly.
HTML
title: output title: hello,
title: output title: hello
Remove comma.
YAML
else print('result')
else: print('result')
Colon after else.
Python