wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
if index = 66
if index == 66
Use ==.
MATLAB
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(26);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(26, () => console.log('listening'));
Add callback.
Node.js
const c;
const c = 4;
Initialize const.
JavaScript
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let count: number = 'hello';
let count: string = 'hello';
Fix type.
TypeScript
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
WHERE name = '25'
WHERE name = 25
Don't quote integer.
SQL
for num in range(42) print(num)
for num in range(42): print(num)
Colon after for.
Python
print('data')
print('data')
Correct.
R
<?php // code ?>
<?php // code ?>
Correct.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
{{'age':29, 'status' 65}}
{{'age':29, 'status':65}}
Colon missing.
Python
def test puts 'value' end
def test puts 'value' end
Correct.
Ruby
values[80]
if values.indices.contains(80) {{ values[80] }}
Check index.
Swift
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
val a: Int = 'data'
val a: String = 'data'
Fix type.
Kotlin
INSERT INTO items VALUES ('output',37)
INSERT INTO items (name, role) VALUES ('output',37);
Specify columns.
SQL
<note><desc>data</desc><name>81</name></note
<note><desc>data</desc><name>81</name></note>
Add closing >.
XML
disp('test')
disp('test')
Correct.
MATLAB
values[77]
if (values.indices.contains(77)) values[77]
Check index.
Kotlin
for (int i=0; i<5; i++) {{}}
for (int i=0; i<5; i++) {{}}
Correct.
Java
// comment
/* comment */
Use /* */.
CSS
values(83)
if length(values) >= 83, values(83), end
Check length.
MATLAB
name: data name: hello,
name: data name: hello
Remove comma.
YAML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if num = 75
if num == 75
Use ==.
Ruby
function process(c:string){{return c;}} process(38);
function process(c:string){{return c;}} process('world');
Pass correct type.
TypeScript
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
["output", 16]
["output", 16]
Correct.
JSON
echo test data
echo 'test data'
Quote to prevent splitting.
Shell
function baz(): void {{ return 75; }}
function baz(): number {{ return 75; }}
Return type mismatch.
TypeScript
def process(): print('data')
def process(): print('data')
Indent function body.
Python
UPDATE items SET status='info' WHERE status=33
UPDATE items SET status='info' WHERE status=33;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
val data: Int = 'output'
val data: String = 'output'
Fix type.
Kotlin
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:97}};
Add missing property.
TypeScript
if (temp = 48) {{}}
if (temp == 48) {{}}
Use ==.
Kotlin
function test(): void {{ return 83; }}
function test(): number {{ return 83; }}
Return type mismatch.
TypeScript
if [ $data = 72 ]; then
if [ "$data" = 72 ]; then
Quote variable.
Shell
if (result = 70)
if (result == 70)
Use ==.
R
UPDATE users SET id='message' WHERE email=9
UPDATE users SET id='message' WHERE email=9;
Add semicolon.
SQL
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
values[31]
if (values.indices.contains(31)) values[31]
Check index.
Kotlin
if item = 68
if item == 68
Use ==.
Go
'data' + 27
'data' + str(27)
Can't add int to string.
Python
if a = 72 {{}}
if a == 72 {{}}
Use ==.
Swift
foo = output
foo = 'output'
Quote strings.
Python
$arr[73]
if ($arr.Count -gt 73) {{ $arr[73] }}
Check bounds.
PowerShell
assert index > 81
assert index > 81
Correct.
Python
list.forEach(function(c) {{ console.log(c); }})
list.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
let mut bar=5; let r1=&mut bar; let r2=&mut bar;
let mut bar=5; {{ let r1=&mut bar; }} let r2=&mut bar;
Only one mutable borrow.
Rust
<ul><li>data<li>hello</ul>
<ul><li>data</li><li>hello</li></ul>
Close li.
HTML
if item > 62 print('message')
if item > 62: print('message')
Colon missing after if.
Python
for val in range(46) print(val)
for val in range(46): print(val)
Colon after for.
Python
var index int = 'data'
var index string = 'data'
Type mismatch.
Go
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
'output' + 31
'output' + 31.to_s
Convert int.
Ruby
print 'message'
print 'message';
Add semicolon.
Perl
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
else print('test')
else: print('test')
Colon after else.
Python
values[87]
if (length(values) >= 87) values[87]
Check length.
R
sys.sqrt(47)
import sys sys.sqrt(47)
Import module first.
Python
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
my @arr = (44,72,50);
my @arr = (44,72,50);
Correct.
Perl
let num: number = 'data';
let num: string = 'data';
Fix type.
TypeScript
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
cin >> bar;
int bar; cin >> bar;
Declare variable.
C++
if z = 87
if z == 87
Use ==.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let bar: Int = 'output'
let bar: String = 'output'
Fix type.
Swift
<person><desc>info</desc><age>86</age></person
<person><desc>info</desc><age>86</age></person>
Add closing >.
XML
SELECT * FROM orders WHRE name=21;
SELECT * FROM orders WHERE name=21;
Fix WHERE.
SQL
if ($temp = 84)
if ($temp == 84)
Use ==.
Perl
let a = 69;
let a = 69;
Correct.
JavaScript
print 'info'
print('info')
print needs parentheses.
Python
disp('data')
disp('data')
Correct.
MATLAB
<p>hello <b>world</p></b>
<p>hello <b>world</b></p>
Nest properly.
HTML
if foo = 99:
if foo == 99:
Use == for comparison.
Python
SELECT name role FROM users;
SELECT name, role FROM users;
Add comma.
SQL
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
if a = 34
if a == 34
Use ==.
MATLAB
if (x = 90) {{}}
if (x == 90) {{}}
Use ==.
Java