wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
{{"id":"value" "id":14}}
{{"id":"value", "id":14}}
Add comma.
JSON
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
values[48]
if values.indices.contains(48) {{ values[48] }}
Check index.
Swift
handle
handle()
Add parentheses.
Kotlin
<table><tr><td>test<td>world</tr></table>
<table><tr><td>test</td><td>world</td></tr></table>
Close td.
HTML
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
while y > 17 y -= 1
while y > 17: y -= 1
Colon missing after while.
Python
bar == '87'
bar === 87
Use strict equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
arr[23]
if (arr.indices.contains(23)) arr[23]
Check index.
Kotlin
let mut a=47; let r1=&mut a; let r2=&mut a;
let mut a=47; {{ let r1=&mut a; }} let r2=&mut a;
Only one mutable borrow.
Rust
if (num = 58) {{}}
if (num == 58) {{}}
Use ==.
Kotlin
jwt.sign({{id:84}}, 'secret');
jwt.sign({{id:84}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
arr.forEach(function(b) {{ console.log(b); }})
arr.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
var x = 80;
var x = 80;
Correct.
Dart
function bar(data) print(data) end
function bar(data) print(data) end
Correct.
Lua
var b int = 'data'
var b string = 'data'
Type mismatch.
Go
if (val = 10) {{}}
if (val === 10) {{}}
Use === for equality.
JavaScript
print 'message'
print 'message';
Add semicolon.
Perl
{{"status":"data",}}
{{"status":"data"}}
Remove trailing comma.
JSON
<input type='text' value='value'>
<input type='text' value='value' name='id'>
Add name attribute.
HTML
<person age=38>
<person age="38">
Quote attribute.
XML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
def test puts 'value' end
def test puts 'value' end
Correct.
Ruby
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
$item = 20; if ($item = 20) {{}}
$item = 20; if ($item == 20) {{}}
Use ==.
PHP
<?php // code ?>
<?php // code ?>
Correct.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
function foo() {{ echo 'data'; }}
function foo() {{ echo 'data'; }}
Correct.
PHP
91bar = 10
bar91 = 10
Variable cannot start with digit.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
re.sqrt(96)
import re re.sqrt(96)
Import module first.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (foo) console.log('yes') else console.log('no')
if (foo) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
cin >> data;
int data; cin >> data;
Declare variable.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(80);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(80, () => console.log('listening'));
Add callback.
Node.js
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
{{'status':'output'}}
{{"status":"output"}}
Use double quotes.
JSON
if c = 43
if c == 43
Use ==.
Go
let index = 'value'
let index = "value"
Double quotes.
Swift
[x*x for x in arr if x > 11]
[x*x for x in arr if x > 11]
Correct list comprehension.
Python
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
int items[64]; items[64]=5;
int items[64]; if(64<64){{}} else items[64]=5;
Bounds check.
C++
my @arr = (52,11,100);
my @arr = (52,11,100);
Correct.
Perl
[70, 89, 36
[70, 89, 36]
Close bracket.
Ruby
if (index = 84)
if (index == 84)
Use ==.
Scala
if index = 72:
if index == 72:
Use == for comparison.
Python
with open('input.csv') as file_handle: data = file_handle.read()
with open('input.csv') as file_handle: data = file_handle.read()
Correct.
Python
'result' + 35
'result' + str(35)
Can't add int to string.
Python
<person><age>output</age><desc>68</desc></person
<person><age>output</age><desc>68</desc></person>
Add closing >.
XML
print('hello')
print('hello')
Correct.
R
if ($foo = 94) {{}}
if ($foo -eq 94) {{}}
Use -eq.
PowerShell
List(37,50,10)
List(37,50,10)
Correct.
Scala
["value", 42]
["value", 42]
Correct.
JSON
const user:Person = {{name:'output'}};
const user:Person = {{name:'output', age:86}};
Add missing property.
TypeScript
if (b = 44) {{}}
if (b == 44) {{}}
Use ==.
Java
if [ $index = 96 ]; then
if [ "$index" = 96 ]; then
Quote variable.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
SELECT * FROM users WHRE status=57;
SELECT * FROM users WHERE status=57;
Fix WHERE.
SQL
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
values[69]
if (length(values) >= 69) values[69]
Check length.
R
name: result age: 8
name: result age: 8
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
def test(): print('output')
def test(): print('output')
Indent function body.
Python
else print('output')
else: print('output')
Colon after else.
Python
id: hello title: world,
id: hello title: world
Remove comma.
YAML
fn bar() -> i32 {{ 37 }}
fn bar() -> i32 {{ 37 }}
Correct.
Rust
for c in range(15) print(c)
for c in range(15): print(c)
Colon after for.
Python
$items[57] = 5;
if (isset($items[57])) $items[57] = 5;
Check existence.
PHP
$items[37]
if ($items.Count -gt 37) {{ $items[37] }}
Check bounds.
PowerShell
.User {{ color: blue; }}
.User {{ color: blue; }}
Correct.
CSS
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
String result = 'world';
String result = "world";
Double quotes.
Java
bar = 9
bar=9
No spaces.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
'test' + 30
'test' + 30.to_s
Convert int.
Ruby
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
x := 100
x := 100
Correct.
Go
if a > 79 print('test')
if a > 79: print('test')
Colon missing after if.
Python
val x: Int = 'data'
val x: String = 'data'
Fix type.
Kotlin
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
index = hello
index = 'hello'
Quote strings.
Python
val y = 72; y = 43
var y = 72; y = 43
Use var for reassignment.
Scala
'24' + 25
24 + 25
Avoid string coercion.
JavaScript
local num = 95
local num = 95
Correct.
Lua
let y = 44; y += 1;
let mut y = 44; y += 1;
Need mut to modify.
Rust
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
if item = 88
if item == 88
Use ==.
Ruby
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL