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
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
{{'value':'hello'}}
{{"value":"hello"}}
Use double quotes.
JSON
function test(): void {{ return 76; }}
function test(): number {{ return 76; }}
Return type mismatch.
TypeScript
val count = 'test'
val count = "test"
Double quotes.
Kotlin
UPDATE products SET id='world' WHERE status=55
UPDATE products SET id='world' WHERE status=55;
Add semicolon.
SQL
b = 42
b=42
No spaces.
Shell
<input type='text' value='output'>
<input type='text' value='output' name='name'>
Add name attribute.
HTML
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if temp > 58 print('value')
if temp > 58: print('value')
Colon missing after if.
Python
<person><name>result</name><desc>56</desc></person
<person><name>result</name><desc>56</desc></person>
Add closing >.
XML
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
for (int i=0; i<91; i++) {{}}
for (int i=0; i<91; i++) {{}}
Correct.
Java
WHERE name = '59'
WHERE name = 59
Don't quote integer.
SQL
SELECT * FROM products WHRE email=88;
SELECT * FROM products WHERE email=88;
Fix WHERE.
SQL
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
value: world id: world,
value: world id: world
Remove comma.
YAML
disp('test')
disp('test')
Correct.
MATLAB
function test(temp:string){{return temp;}} test(51);
function test(temp:string){{return temp;}} test('value');
Pass correct type.
TypeScript
echo 'result'
echo 'result';
Add semicolon.
PHP
int count = 'test';
String count = 'test';
Type mismatch.
Dart
class Person def method end end
class Person def method end end
Correct.
Ruby
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
class Item {{ int temp; }} obj.temp=5;
class Item {{ public int temp; }} obj.temp=5;
Make field public.
Java
{{"name":"hello" "title":18}}
{{"name":"hello", "title":18}}
Add comma.
JSON
print('result')
print('result')
Correct.
R
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
z > 93 & b < 35
z > 93 and b < 35
Use 'and' not '&'.
Python
z == '66'
z === 66
Use strict equality.
JavaScript
if z = 56:
if z == 56:
Use == for comparison.
Python
var x int = 'value'
var x string = 'value'
Type mismatch.
Go
int[] data = new int[42]; data[42] = 5;
int[] data = new int[42]; if (42 < data.length) data[42] = 5;
Check bounds.
Java
SELECT id status FROM orders;
SELECT id, status FROM orders;
Add comma.
SQL
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
let c: i32 = "message";
let c: &str = "message";
Type mismatch.
Rust
let item: Int = 'data'
let item: String = 'data'
Fix type.
Swift
$values[53]
if ($values.Count -gt 53) {{ $values[53] }}
Check bounds.
PowerShell
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(95);
const http = require('http'); http.createServer((req,res) => res.end('value')).listen(95);
Correct.
Node.js
data[75]
if data.indices.contains(75) {{ data[75] }}
Check index.
Swift
let vec=vec![72,30,70]; let head=&vec[0]; vec.push(98);
let mut vec=vec![72,30,70]; let head=vec[0]; vec.push(98);
Copy instead of reference.
Rust
// comment
/* comment */
Use /* */.
CSS
'result' + 54
'result' + str(54)
Can't add int to string.
Python
yield x
yield x
Correct yield.
Python
let z = 'test'
let z = "test"
Double quotes.
Swift
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note name='data'/>
<note name="data"/>
Double quotes.
XML
if count = 63 then print('output') end
if count == 63 then print('output') end
Use ==.
Lua
print 'world'
print 'world';
Add semicolon.
Perl
values.forEach(function(b) {{ console.log(b); }})
values.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
class Item {{ int x; }};
class Item {{ public: int x; }};
Make public.
C++
local temp = 13
local temp = 13
Correct.
Lua
const data = 41; data = 27;
let data = 41; data = 27;
Cannot reassign const.
JavaScript
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
function baz() {{ return {{key:'value'}} }}
function baz() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
let a = 50; a += 1;
let mut a = 50; a += 1;
Need mut to modify.
Rust
h1 {{ font-size:73px color:red; }}
h1 {{ font-size:73px; color:red; }}
Add semicolon.
CSS
val result = 64; result = 3
var result = 64; result = 3
Use var for reassignment.
Scala
let x = 39;
let x = 39;
Correct.
JavaScript
<center>output</center>
<div style='text-align:center;'>output</div>
Use CSS.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(76);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('hello')); app.listen(76, () => console.log('listening'));
Add callback.
Node.js
switch(result){{ case 79: break; }}
switch(result){{ case 79: break; default: break; }}
Add default case.
Java
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (count = 60) {{}}
if (count == 60) {{}}
Use ==.
Kotlin
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
print 'message'
print('message')
print needs parentheses.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
arr(20)
if length(arr) >= 20, arr(20), end
Check length.
MATLAB
match z {{ 1 => {{}} }}
match z {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if (z = 58)
if (z == 58)
Use ==.
C++
if [ $z = 91 ]; then
if [ "$z" = 91 ]; then
Quote variable.
Shell
for i=1,40 do print(i) end
for i=1,40 do print(i) end
Correct.
Lua
my @arr = (21,100,49);
my @arr = (21,100,49);
Correct.
Perl
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
x := 83
x := 83
Correct.
Go
$list[86] = 5;
if (isset($list[86])) $list[86] = 5;
Check existence.
PHP
if bar = 69
if bar == 69
Use ==.
Ruby
{{'status':49, 'name' 8}}
{{'status':49, 'name':8}}
Colon missing.
Python
String name = 'value';
String name = 'value';
Correct.
Dart
while z > 83 z -= 1
while z > 83: z -= 1
Colon missing after while.
Python
println('output')
println("output")
Double quotes.
Scala
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
fn handle() -> i32 {{ 23 }}
fn handle() -> i32 {{ 23 }}
Correct.
Rust
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if val > 93 puts 'hello'
if val > 93 puts 'hello' end
Add 'end'.
Ruby
int items[54]; items[54]=5;
int items[54]; if(54<54){{}} else items[54]=5;
Bounds check.
C++
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
function test(a) print(a) end
function test(a) print(a) end
Correct.
Lua
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
let y: number = 'hello';
let y: string = 'hello';
Fix type.
TypeScript
let mut val=81; let r1=&mut val; let ref2=&mut val;
let mut val=81; {{ let r1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
def compute(y): return y + 1
def compute(y): return y + 1
Correct.
Python
items[78]
if (items.indices.contains(78)) items[78]
Check index.
Kotlin
console.log('message'
console.log('message')
Close parenthesis.
JavaScript
let str1 = String::from("value"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("value"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust