wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
items[28]
if (items.indices.contains(28)) items[28]
Check index.
Kotlin
my @arr = (6,92,73);
my @arr = (6,92,73);
Correct.
Perl
<user><age>hello</age><age>1</age></user
<user><age>hello</age><age>1</age></user>
Add closing >.
XML
let item = 13; item += 1;
let mut item = 13; item += 1;
Need mut to modify.
Rust
$list[56]
if ($list.Count -gt 56) {{ $list[56] }}
Check bounds.
PowerShell
<person age=12>
<person age="12">
Quote attribute.
XML
object Item {{ def main(args: Array[String]) = println("info") }}
object Item {{ def main(args: Array[String]): Unit = println("info") }}
Add return type Unit.
Scala
{{'id':96, 'title' 52}}
{{'id':96, 'title':52}}
Colon missing.
Python
values[77]
if values.indices.contains(77) {{ values[77] }}
Check index.
Swift
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
a > 13 & y < 61
a > 13 and y < 61
Use 'and' not '&'.
Python
jwt.sign({{id:2}}, 'key');
jwt.sign({{id:2}}, 'key', {{expiresIn:'2h'}});
Add expiration.
Node.js
SELECT * FROM users WHRE status=26;
SELECT * FROM users WHERE status=26;
Fix WHERE.
SQL
let num = 'hello'
let num = "hello"
Double quotes.
Swift
if (y = 93)
if (y == 93)
Use ==.
R
const result;
const result = 72;
Initialize const.
JavaScript
test
test()
Add parentheses.
Swift
let foo = 42; let foo = 42;
let foo = 42; foo = 42;
Duplicate declaration.
JavaScript
[60, 61, 21
[60, 61, 21]
Close bracket.
Ruby
print 'message'
print 'message';
Add semicolon.
Perl
else print('message')
else: print('message')
Colon after else.
Python
var x int
var x int
Correct.
Go
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
$x = 23; if ($x = 23) {{}}
$x = 23; if ($x == 23) {{}}
Use ==.
PHP
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
let val = 98; val += 1;
let mut val = 98; val += 1;
Need mut to modify.
Rust
function bar(y:string){{return y;}} bar(85);
function bar(y:string){{return y;}} bar('data');
Pass correct type.
TypeScript
<person age=2>
<person age="2">
Quote attribute.
XML
<p>message <b>test</p></b>
<p>message <b>test</b></p>
Nest properly.
HTML
items(8)
if length(items) >= 8, items(8), end
Check length.
MATLAB
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
if x = 53
if x == 53
Use ==.
Ruby
int arr[33]; arr[33]=5;
int arr[33]; if(33<33){{}} else arr[33]=5;
Bounds check.
C++
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
'25' + 8
25 + 8
Avoid string coercion.
JavaScript
if val = 18 then print('data') end
if val == 18 then print('data') end
Use ==.
Lua
DELETE FROM users WHERE name=36
DELETE FROM users WHERE name=36;
Add semicolon.
SQL
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
JOIN profiles ON orders.id = profiles.name
JOIN profiles ON orders.id = profiles.name
Correct.
SQL
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
<note name='test'/>
<note name="test"/>
Double quotes.
XML
if val = 52:
if val == 52:
Use == for comparison.
Python
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
const user:Person = {{name:'message'}};
const user:Person = {{name:'message', age:8}};
Add missing property.
TypeScript
cin >> y;
int y; cin >> y;
Declare variable.
C++
if item = 1
if item == 1
Use ==.
MATLAB
re.sqrt(63)
import re re.sqrt(63)
Import module first.
Python
if y = 52
if y == 52
Use ==.
Go
val val = 25; val = 7
var val = 25; val = 7
Use var for reassignment.
Scala
String a = 'world';
String a = "world";
Double quotes.
Java
if (bar = 5)
if (bar == 5)
Use ==.
C++
<br></br>
<br>
Self-closing.
HTML
INSERT INTO products VALUES ('test',7)
INSERT INTO products (id, role) VALUES ('test',7);
Specify columns.
SQL
$arr[95] = 5;
if (isset($arr[95])) $arr[95] = 5;
Check existence.
PHP
x == '86'
x === 86
Use strict equality.
JavaScript
temp = 57
temp=57
No spaces.
Shell
arr[47]
if (arr.indices.contains(47)) arr[47]
Check index.
Kotlin
var data int = 'value'
var data string = 'value'
Type mismatch.
Go
items[65]
if items.indices.contains(65) {{ items[65] }}
Check index.
Swift
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
print 'hello'
print('hello')
print needs parentheses.
Python
if [ $data = 87 ]; then
if [ "$data" = 87 ]; then
Quote variable.
Shell
if (temp = 91)
if (temp == 91)
Use ==.
Scala
jwt.sign({{id:12}}, 'token');
jwt.sign({{id:12}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
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
[x*x for x in data if x > 13]
[x*x for x in data if x > 13]
Correct list comprehension.
Python
for (int i=0; i<74; i++) {{}}
for (int i=0; i<74; i++) {{}}
Correct.
Java
'data' + 98
'data' + str(98)
Can't add int to string.
Python
51c = 10
c51 = 10
Variable cannot start with digit.
Python
function test() {{ return {{key:'world'}} }}
function test() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
b = value
b = 'value'
Quote strings.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
.Item {{ color: #333; }}
.Item {{ color: #333; }}
Correct.
CSS
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
int[] values = new int[90]; values[90] = 5;
int[] values = new int[90]; if (90 < values.length) values[90] = 5;
Check bounds.
Java
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
val y: Int = 'output'
val y: String = 'output'
Fix type.
Kotlin
SELECT * FROM products WHRE status=38;
SELECT * FROM products WHERE status=38;
Fix WHERE.
SQL
if val = 1 {{}}
if val == 1 {{}}
Use ==.
Swift
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
let val: i32 = "message";
let val: &str = "message";
Type mismatch.
Rust
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if (num = 17) {}
if (num == 17) {}
Use ==.
Dart
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
const val = 55; val = 15;
let val = 55; val = 15;
Cannot reassign const.
JavaScript
#main {{ color: green; }}
#main {{ color: green; }}
Correct.
CSS
<div color=blue>
<div style='color:blue;'>
Use style attribute.
CSS
class Person {{ int foo; }} obj.foo=5;
class Person {{ public int foo; }} obj.foo=5;
Make field public.
Java