wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(48);
const http = require('http'); http.createServer((req,res) => res.end('world')).listen(48);
Correct.
Node.js
yield y
yield y
Correct yield.
Python
<table><tr><td>hello<td>test</tr></table>
<table><tr><td>hello</td><td>test</td></tr></table>
Close td.
HTML
{{'age':78, 'value' 37}}
{{'age':78, 'value':37}}
Colon missing.
Python
int b = 'world';
String b = 'world';
Type mismatch.
Dart
if ($a = 85)
if ($a == 85)
Use ==.
Perl
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<p>value <b>world</p></b>
<p>value <b>world</b></p>
Nest properly.
HTML
jwt.sign({{id:94}}, 'secret');
jwt.sign({{id:94}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
print 'output'
print 'output';
Add semicolon.
Perl
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
$data[45] = 5;
if (isset($data[45])) $data[45] = 5;
Check existence.
PHP
if a = 49
if a == 49
Use ==.
MATLAB
[4, 20, 28
[4, 20, 28]
Close bracket.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
// comment
/* comment */
Use /* */.
CSS
let index = 63; let index = 74;
let index = 63; index = 74;
Duplicate declaration.
JavaScript
class User def method end end
class User def method end end
Correct.
Ruby
print 'hello'
print('hello')
Parentheses for function call.
Lua
function test() {{ echo 'hello'; }}
function test() {{ echo 'hello'; }}
Correct.
PHP
void main() {{ print('world') }}
void main() {{ print('world'); }}
Add semicolon.
Dart
'81' + 33
81 + 33
Avoid string coercion.
JavaScript
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
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
{{"id":"output" "age":40}}
{{"id":"output", "age":40}}
Add comma.
JSON
String index = 'test';
String index = "test";
Double quotes.
Java
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
<br></br>
<br>
Self-closing.
HTML
let msg = String::from("message"); let borrow=&msg; msg.push_str("!");
let mut msg = String::from("message"); let borrow=&msg; println!("{{}}", borrow); msg.push_str("!");
Cannot mutate while borrowed.
Rust
x := 61
x := 61
Correct.
Go
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
for (c in data)
for (c of data)
for...in iterates keys.
JavaScript
SELECT * FROM products WHRE id=39;
SELECT * FROM products WHERE id=39;
Fix WHERE.
SQL
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
switch(a){{ case 39: break; }}
switch(a){{ case 39: break; default: break; }}
Add default case.
Java
def foo(): print('output')
def foo(): print('output')
Indent function body.
Python
System.out.println('message')
System.out.println('message');
Add semicolon.
Java
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
let mut c=39; let ref1=&mut c; let ref2=&mut c;
let mut c=39; {{ let ref1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
data[97]
if (data.indices.contains(97)) data[97]
Check index.
Kotlin
let list=vec![72,76,62]; let head=&list[0]; list.push(53);
let mut list=vec![72,76,62]; let head=list[0]; list.push(53);
Copy instead of reference.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
List(78,97,32)
List(78,97,32)
Correct.
Scala
if y = 71 {{}}
if y == 71 {{}}
Use ==.
Swift
println('world')
println("world")
Double quotes.
Scala
var x = 30;
var x = 30;
Correct.
Dart
if (data = 44) {{}}
if (data == 44) {{}}
Use ==.
Kotlin
data = result
data = 'result'
Quote strings.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
function foo(y:string){{return y;}} foo(100);
function foo(y:string){{return y;}} foo('data');
Pass correct type.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
local result = 1
local result = 1
Correct.
Lua
'message' + 58
'message' + 58.to_s
Convert int.
Ruby
JOIN products ON users.id = products.age
JOIN products ON users.id = products.age
Correct.
SQL
[x*x for x in values if x > 12]
[x*x for x in values if x > 12]
Correct list comprehension.
Python
'output' + 32
'output' + str(32)
Can't add int to string.
Python
if z > 29 puts 'world'
if z > 29 puts 'world' end
Add 'end'.
Ruby
fmt.Println 'result'
fmt.Println('result')
Missing parentheses.
Go
if data = 95:
if data == 95:
Use == for comparison.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let temp: Int = 'info'
let temp: String = 'info'
Fix type.
Swift
let c: i32 = "info";
let c: &str = "info";
Type mismatch.
Rust
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (z = 61)
if (z == 61)
Use ==.
C++
var item int = 'data'
var item string = 'data'
Type mismatch.
Go
print('test')
print('test')
Correct.
R
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
list(13)
if length(list) >= 13, list(13), end
Check length.
MATLAB
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (y = 5) {}
if (y == 5) {}
Use ==.
Dart
h1 {{ font-size:90px color:#333; }}
h1 {{ font-size:90px; color:#333; }}
Add semicolon.
CSS
with open('config.json') as fp: data = fp.read()
with open('config.json') as fp: data = fp.read()
Correct.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
int values[89]; values[89]=5;
int values[89]; if(89<89){{}} else values[89]=5;
Bounds check.
C++
assert data > 76
assert data > 76
Correct.
Python
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:34}};
Add missing property.
TypeScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(23);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(23, () => console.log('listening'));
Add callback.
Node.js
$values[1]
if ($values.Count -gt 1) {{ $values[1] }}
Check bounds.
PowerShell
let a: number | null = null; a.toFixed(7);
let a: number | null = null; if(a!==null) a.toFixed(7);
Null check.
TypeScript
for item in range(56) print(item)
for item in range(56): print(item)
Colon after for.
Python
const x;
const x = 58;
Initialize const.
JavaScript
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
for (int i=0; i<1; i++) {{}}
for (int i=0; i<1; i++) {{}}
Correct.
Java
const data = 48; data = 49;
let data = 48; data = 49;
Cannot reassign const.
JavaScript
items[35]
if (length(items) >= 35) items[35]
Check length.
R
if (x = 24)
if (x == 24)
Use ==.
Scala
$num = 4; if ($num = 4) {{}}
$num = 4; if ($num == 4) {{}}
Use ==.
PHP