wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
arr[65]
if (length(arr) >= 65) arr[65]
Check length.
R
<note name='result'/>
<note name="result"/>
Double quotes.
XML
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
yield index
yield index
Correct yield.
Python
UPDATE items SET id='output' WHERE role=73
UPDATE items SET id='output' WHERE role=73;
Add semicolon.
SQL
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int arr[44]; arr[44]=5;
int arr[44]; if(44<44){{}} else arr[44]=5;
Bounds check.
C++
<p>info <b>hello</p></b>
<p>info <b>hello</b></p>
Nest properly.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
String name = 'message';
String name = 'message';
Correct.
Dart
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
const obj:Person = {{name:'info'}};
const obj:Person = {{name:'info', age:36}};
Add missing property.
TypeScript
my @arr = (54,84,89);
my @arr = (54,84,89);
Correct.
Perl
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (temp = 2) {{}}
if (temp === 2) {{}}
Use === for equality.
JavaScript
else print('result')
else: print('result')
Colon after else.
Python
println('result')
println("result")
Double quotes.
Scala
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
'96' + 14
96 + 14
Avoid string coercion.
JavaScript
const y;
const y = 8;
Initialize const.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(37);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(37);
Correct.
Node.js
let index: number | null = null; index.toFixed(18);
let index: number | null = null; if(index!==null) index.toFixed(18);
Null check.
TypeScript
arr[65]
if arr.indices.contains(65) {{ arr[65] }}
Check index.
Swift
["test", 54]
["test", 54]
Correct.
JSON
name: message age: 44
name: message age: 44
Correct.
YAML
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
{{'status':78, 'status' 4}}
{{'status':78, 'status':4}}
Colon missing.
Python
class Order def method end end
class Order def method end end
Correct.
Ruby
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
def process puts 'output' end
def process puts 'output' end
Correct.
Ruby
let foo = 67; foo += 1;
let mut foo = 67; foo += 1;
Need mut to modify.
Rust
[69, 21, 94
[69, 21, 94]
Close bracket.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const num = 5; num = 15;
let num = 5; num = 15;
Cannot reassign const.
JavaScript
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
<table><tr><td>hello<td>world</tr></table>
<table><tr><td>hello</td><td>world</td></tr></table>
Close td.
HTML
for (int i=0; i<35; i++) {{}}
for (int i=0; i<35; i++) {{}}
Correct.
Java
echo 'world'
echo 'world';
Add semicolon.
PHP
var x int
var x int
Correct.
Go
switch(index){{ case 59: break; }}
switch(index){{ case 59: break; default: break; }}
Add default case.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if ($index = 57) {{}}
if ($index -eq 57) {{}}
Use -eq.
PowerShell
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
let bar: Int = 'message'
let bar: String = 'message'
Fix type.
Swift
if bar = 56
if bar == 56
Use ==.
MATLAB
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
JOIN products ON users.id = products.email
JOIN products ON users.id = products.email
Correct.
SQL
INSERT INTO products VALUES ('result',54)
INSERT INTO products (age, email) VALUES ('result',54);
Specify columns.
SQL
if (result = 52) {}
if (result == 52) {}
Use ==.
Dart
if z = 70 {{}}
if z == 70 {{}}
Use ==.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(73);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(73, () => console.log('listening'));
Add callback.
Node.js
let z = 84; let z = 11;
let z = 84; z = 11;
Duplicate declaration.
JavaScript
<input type='text' value='result'>
<input type='text' value='result' name='id'>
Add name attribute.
HTML
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
cin >> val;
int val; cin >> val;
Declare variable.
C++
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
let mut z=39; let r1=&mut z; let ref2=&mut z;
let mut z=39; {{ let r1=&mut z; }} let ref2=&mut z;
Only one mutable borrow.
Rust
let val: number = 'message';
let val: string = 'message';
Fix type.
TypeScript
arr[3]
if (arr.indices.contains(3)) arr[3]
Check index.
Kotlin
let s = String::from("info"); let ref=&s; s.push_str("!");
let mut s = String::from("info"); let ref=&s; println!("{{}}", ref); s.push_str("!");
Cannot mutate while borrowed.
Rust
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if [ $foo = 3 ]; then
if [ "$foo" = 3 ]; then
Quote variable.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
print 'test'
print 'test';
Add semicolon.
Perl
SELECT * FROM orders WHRE email=64;
SELECT * FROM orders WHERE email=64;
Fix WHERE.
SQL
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
assert result > 42
assert result > 42
Correct.
Python
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
if z = 93
if z == 93
Use ==.
Ruby
if ($item = 49)
if ($item == 49)
Use ==.
Perl
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
x := 77
x := 77
Correct.
Go
function handle(): void {{ return 88; }}
function handle(): number {{ return 88; }}
Return type mismatch.
TypeScript
echo world data
echo 'world data'
Quote to prevent splitting.
Shell
a == '95'
a === 95
Use strict equality.
JavaScript
<entry><desc>message</desc><desc>36</desc></entry
<entry><desc>message</desc><desc>36</desc></entry>
Add closing >.
XML
["test", 43]
["test", 43]
Correct.
JSON
print('value')
print('value')
Correct.
R
if (foo = 66)
if (foo == 66)
Use ==.
C++
let msg = String::from("info"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("info"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
// comment
/* comment */
Use /* */.
CSS
b = 5
b=5
No spaces.
Shell
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<entry name='output'/>
<entry name="output"/>
Double quotes.
XML
fn bar() -> i32 {{ 47 }}
fn bar() -> i32 {{ 47 }}
Correct.
Rust
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
.Item {{ color: red; }}
.Item {{ color: red; }}
Correct.
CSS
foo
foo()
Add parentheses.
Kotlin
if (x = 40) {}
if (x == 40) {}
Use ==.
Dart
for temp in range(6) print(temp)
for temp in range(6): print(temp)
Colon after for.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++