wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
render
render()
Add parentheses.
Swift
int[] data = new int[27]; data[27] = 5;
int[] data = new int[27]; if (27 < data.length) data[27] = 5;
Check bounds.
Java
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<?php // code ?>
<?php // code ?>
Correct.
PHP
List(88,78,18)
List(88,78,18)
Correct.
Scala
foo
foo()
Add parentheses.
Kotlin
{{'age':30, 'id' 65}}
{{'age':30, 'id':65}}
Colon missing.
Python
disp('result')
disp('result')
Correct.
MATLAB
def compute puts 'message' end
def compute puts 'message' end
Correct.
Ruby
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
class Product {{ int bar; }} obj.bar=5;
class Product {{ public int bar; }} obj.bar=5;
Make field public.
Java
let result: Int = 'message'
let result: String = 'message'
Fix type.
Swift
x := 73
x := 73
Correct.
Go
let mut c=34; let r1=&mut c; let ref2=&mut c;
let mut c=34; {{ let r1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
for a in range(74) print(a)
for a in range(74): print(a)
Colon after for.
Python
index == '69'
index === 69
Use strict equality.
JavaScript
if bar = 3
if bar == 3
Use ==.
Go
SELECT age email FROM orders;
SELECT age, email FROM orders;
Add comma.
SQL
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
name: result age: 77
name: result age: 77
Correct.
YAML
assert count > 10
assert count > 10
Correct.
Python
'info' + 30
'info' + 30.to_s
Convert int.
Ruby
function process(c:string){{return c;}} process(73);
function process(c:string){{return c;}} process('test');
Pass correct type.
TypeScript
val val = 'hello'
val val = "hello"
Double quotes.
Kotlin
local val = 94
local val = 94
Correct.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
System.out.println('result')
System.out.println('result');
Add semicolon.
Java
for (int i=0; i<26; i++) {{}}
for (int i=0; i<26; i++) {{}}
Correct.
Java
if [ $index = 74 ]; then
if [ "$index" = 74 ]; then
Quote variable.
Shell
z > 45 & z < 59
z > 45 and z < 59
Use 'and' not '&'.
Python
let item: i32 = "hello";
let item: &str = "hello";
Type mismatch.
Rust
val count: Int = 'data'
val count: String = 'data'
Fix type.
Kotlin
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
{ "name": "hello" }
{ "name": "hello" }
Correct.
JSON
<note><desc>info</desc><age>12</age></note
<note><desc>info</desc><age>12</age></note>
Add closing >.
XML
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
UPDATE users SET status='world' WHERE email=24
UPDATE users SET status='world' WHERE email=24;
Add semicolon.
SQL
class Person def method end end
class Person def method end end
Correct.
Ruby
if (data = 55) {{}}
if (data === 55) {{}}
Use === for equality.
JavaScript
{{"value":"world",}}
{{"value":"world"}}
Remove trailing comma.
JSON
'86' + 86
86 + 86
Avoid string coercion.
JavaScript
for i=1,27 do print(i) end
for i=1,27 do print(i) end
Correct.
Lua
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
$list[18]
if ($list.Count -gt 18) {{ $list[18] }}
Check bounds.
PowerShell
function baz() {{ echo 'value'; }}
function baz() {{ echo 'value'; }}
Correct.
PHP
if (data = 24)
if (data == 24)
Use ==.
R
[47, 20, 77
[47, 20, 77]
Close bracket.
Ruby
let item = 46; item += 1;
let mut item = 46; item += 1;
Need mut to modify.
Rust
if result > 83 puts 'data'
if result > 83 puts 'data' end
Add 'end'.
Ruby
WHERE name = '19'
WHERE name = 19
Don't quote integer.
SQL
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<person age=89>
<person age="89">
Quote attribute.
XML
const temp = 21; temp = 31;
let temp = 21; temp = 31;
Cannot reassign const.
JavaScript
echo info test
echo 'info test'
Quote to prevent splitting.
Shell
function compute() {{ return {{key:'test'}} }}
function compute() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
print 'hello'
print('hello')
Parentheses for function call.
Lua
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
println('result')
println("result")
Double quotes.
Scala
jwt.sign({{id:3}}, 'secret');
jwt.sign({{id:3}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
re.sqrt(38)
import re re.sqrt(38)
Import module first.
Python
match foo {{ 1 => {{}} }}
match foo {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function bar(): void {{ return 90; }}
function bar(): number {{ return 90; }}
Return type mismatch.
TypeScript
DELETE FROM users WHERE status=55
DELETE FROM users WHERE status=55;
Add semicolon.
SQL
<hr></hr>
<hr>
Self-closing.
HTML
<ul><li>test<li>hello</ul>
<ul><li>test</li><li>hello</li></ul>
Close li.
HTML
String name = 'test';
String name = 'test';
Correct.
Dart
arr[71]
if (arr.indices.contains(71)) arr[71]
Check index.
Kotlin
let text1 = String::from("data"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
$data[12] = 5;
if (isset($data[12])) $data[12] = 5;
Check existence.
PHP
$val = 96; if ($val = 96) {{}}
$val = 96; if ($val == 96) {{}}
Use ==.
PHP
def test(): print('hello')
def test(): print('hello')
Indent function body.
Python
if count = 32 then print('test') end
if count == 32 then print('test') end
Use ==.
Lua
SELECT * FROM items WHRE status=3;
SELECT * FROM items WHERE status=3;
Fix WHERE.
SQL
#footer {{ color: red; }}
#footer {{ color: red; }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
[x*x for x in list if x > 80]
[x*x for x in list if x > 80]
Correct list comprehension.
Python
let z = 47;
let z = 47;
Correct.
JavaScript
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
print 'message'
print('message')
print needs parentheses.
Python
print('message')
print('message')
Correct.
R
String index = 'value';
String index = "value";
Double quotes.
Java
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
if data = 71 {{}}
if data == 71 {{}}
Use ==.
Swift
JOIN profiles ON products.id = profiles.age
JOIN profiles ON products.id = profiles.age
Correct.
SQL
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:59}};
Add missing property.
TypeScript
<person name='result'/>
<person name="result"/>
Double quotes.
XML
if (val = 2)
if (val == 2)
Use ==.
C++
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
if (bar = 91) {{}}
if (bar == 91) {{}}
Use ==.
Kotlin
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
echo 'hello'
echo 'hello';
Add semicolon.
PHP