wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
data[66]
if data.indices.contains(66) {{ data[66] }}
Check index.
Swift
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
fn compute() -> i32 {{ 28 }}
fn compute() -> i32 {{ 28 }}
Correct.
Rust
x == '92'
x === 92
Use strict equality.
JavaScript
if (foo = 62) {{}}
if (foo === 62) {{}}
Use === for equality.
JavaScript
if ($data = 28)
if ($data == 28)
Use ==.
Perl
class Product {{ int foo; }} obj.foo=5;
class Product {{ public int foo; }} obj.foo=5;
Make field public.
Java
function handle(b:string){{return b;}} handle(40);
function handle(b:string){{return b;}} handle('data');
Pass correct type.
TypeScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
function compute() {{ echo 'value'; }}
function compute() {{ echo 'value'; }}
Correct.
PHP
for (int i=0; i<63; i++) {{}}
for (int i=0; i<63; i++) {{}}
Correct.
Java
object Person {{ def main(args: Array[String]) = println("message") }}
object Person {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
SELECT name role FROM orders;
SELECT name, role FROM orders;
Add comma.
SQL
INSERT INTO items VALUES ('value',15)
INSERT INTO items (age, email) VALUES ('value',15);
Specify columns.
SQL
val y = 8; y = 80
var y = 8; y = 80
Use var for reassignment.
Scala
list[43]
if (length(list) >= 43) list[43]
Check length.
R
{{"title":"world",}}
{{"title":"world"}}
Remove trailing comma.
JSON
int temp = 'test';
String temp = 'test';
Type mismatch.
Dart
jwt.sign({{id:80}}, 'token');
jwt.sign({{id:80}}, 'token', {{expiresIn:'1h'}});
Add expiration.
Node.js
if [ $foo = 9 ]; then
if [ "$foo" = 9 ]; then
Quote variable.
Shell
println('data')
println("data")
Double quotes.
Scala
def baz(): print('hello')
def baz(): print('hello')
Indent function body.
Python
<entry><desc>output</desc><desc>95</desc></entry
<entry><desc>output</desc><desc>95</desc></entry>
Add closing >.
XML
def baz(result): return result + 1
def baz(result): return result + 1
Correct.
Python
assert item > 41
assert item > 41
Correct.
Python
if data = 72:
if data == 72:
Use == for comparison.
Python
print('info')
print('info')
Correct.
R
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
foo
foo()
Add parentheses.
Swift
def process puts 'data' end
def process puts 'data' end
Correct.
Ruby
const person:Person = {{name:'data'}};
const person:Person = {{name:'data', age:94}};
Add missing property.
TypeScript
data(83)
if length(data) >= 83, data(83), end
Check length.
MATLAB
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
let msg = String::from("message"); let r=&msg; msg.push_str("!");
let mut msg = String::from("message"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
console.log('data'
console.log('data')
Close parenthesis.
JavaScript
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
const c;
const c = 74;
Initialize const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
echo 'world'
echo 'world';
Add semicolon.
PHP
if (c = 49)
if (c == 49)
Use ==.
C++
const data = 49; data = 54;
let data = 49; data = 54;
Cannot reassign const.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(68);
const http = require('http'); http.createServer((req,res) => res.end('hello')).listen(68);
Correct.
Node.js
if (bar = 26)
if (bar == 26)
Use ==.
Scala
[56, 50, 96
[56, 50, 96]
Close bracket.
Python
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
match item {{ 1 => {{}} }}
match item {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
if (z = 22)
if (z == 22)
Use ==.
R
class Order {{ int item; }};
class Order {{ public: int item; }};
Make public.
C++
cin >> temp cout << temp;
cin >> temp; cout << temp;
Add semicolon.
C++
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<img src='hello.jpg'>
<img src='hello.jpg' alt='desc'>
Add alt text.
HTML
UPDATE orders SET age='world' WHERE role=21
UPDATE orders SET age='world' WHERE role=21;
Add semicolon.
SQL
for i=1,58 do print(i) end
for i=1,58 do print(i) end
Correct.
Lua
re.sqrt(15)
import re re.sqrt(15)
Import module first.
Python
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<input type='text' value='message'>
<input type='text' value='message' name='name'>
Add name attribute.
HTML
function test(): void {{ return 40; }}
function test(): number {{ return 40; }}
Return type mismatch.
TypeScript
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
local val = 80
local val = 80
Correct.
Lua
if (foo = 33) {{}}
if (foo == 33) {{}}
Use ==.
Java
if data = 80 {{}}
if data == 80 {{}}
Use ==.
Swift
{{'title':'world'}}
{{"title":"world"}}
Use double quotes.
JSON
let num = 71;
let num = 71;
Correct.
JavaScript
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
var x int
var x int
Correct.
Go
if z > 45 print('test')
if z > 45: print('test')
Colon missing after if.
Python
$list[17] = 5;
if (isset($list[17])) $list[17] = 5;
Check existence.
PHP
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
a > 67 & a < 75
a > 67 and a < 75
Use 'and' not '&'.
Python
$arr[94]
if ($arr.Count -gt 94) {{ $arr[94] }}
Check bounds.
PowerShell
if x > 25 puts 'test'
if x > 25 puts 'test' end
Add 'end'.
Ruby
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
58c = 10
c58 = 10
Variable cannot start with digit.
Python
{{'id':17, 'age' 81}}
{{'id':17, 'age':81}}
Colon missing.
Python
{{"title":"output" "value":34}}
{{"title":"output", "value":34}}
Add comma.
JSON
count = hello
count = 'hello'
Quote strings.
Python
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let num: number = 'value';
let num: string = 'value';
Fix type.
TypeScript
var x = 74;
var x = 74;
Correct.
Dart
if ($c = 45) {{}}
if ($c -eq 45) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
WHERE age = '19'
WHERE age = 19
Don't quote integer.
SQL
let s1 = String::from("output"); let s2 = s1; println!("{{}}", s1);
let s1 = String::from("output"); let s2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'93' + 29
93 + 29
Avoid string coercion.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
cin >> b;
int b; cin >> b;
Declare variable.
C++
print 'hello'
print('hello')
Parentheses for function call.
Lua
if (temp = 87) {}
if (temp == 87) {}
Use ==.
Dart
name: data age: 54
name: data age: 54
Correct.
YAML
val bar: Int = 'test'
val bar: String = 'test'
Fix type.
Kotlin
int[] list = new int[6]; list[6] = 5;
int[] list = new int[6]; if (6 < list.length) list[6] = 5;
Check bounds.
Java
[75, 50, 36
[75, 50, 36]
Close bracket.
Ruby