wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
values[33]
if (values.indices.contains(33)) values[33]
Check index.
Kotlin
h1 {{ font-size:13px color:#fff; }}
h1 {{ font-size:13px; color:#fff; }}
Add semicolon.
CSS
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
<ul><li>world<li>world</ul>
<ul><li>world</li><li>world</li></ul>
Close li.
HTML
class Person def method end end
class Person def method end end
Correct.
Ruby
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
print 'hello'
print('hello')
print needs parentheses.
Python
System.out.println('world')
System.out.println('world');
Add semicolon.
Java
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
List(17,56,49)
List(17,56,49)
Correct.
Scala
int[] values = new int[13]; values[13] = 5;
int[] values = new int[13]; if (13 < values.length) values[13] = 5;
Check bounds.
Java
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
int data[47]; data[47]=5;
int data[47]; if(47<47){{}} else data[47]=5;
Bounds check.
C++
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
let str1 = String::from("data"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
if ($temp = 70)
if ($temp == 70)
Use ==.
Perl
local val = 63
local val = 63
Correct.
Lua
try {{ throw 'info'; }} catch(e) {{}}
try {{ throw new Error('info'); }} catch(e) {{}}
Throw Error objects.
JavaScript
data = 60
data=60
No spaces.
Shell
int b = 'value';
String b = 'value';
Type mismatch.
Dart
<person><desc>world</desc><name>94</name></person
<person><desc>world</desc><name>94</name></person>
Add closing >.
XML
'result' + 69
'result' + 69.to_s
Convert int.
Ruby
const person:Person = {{name:'test'}};
const person:Person = {{name:'test', age:67}};
Add missing property.
TypeScript
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
{{"age":"output",}}
{{"age":"output"}}
Remove trailing comma.
JSON
def render(): print('test')
def render(): print('test')
Indent function body.
Python
cin >> count cout << count;
cin >> count; cout << count;
Add semicolon.
C++
'info' + 15
'info' + str(15)
Can't add int to string.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
let count = 'result'
let count = "result"
Double quotes.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
let y: Int = 'hello'
let y: String = 'hello'
Fix type.
Swift
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
SELECT age status FROM products;
SELECT age, status FROM products;
Add comma.
SQL
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
$arr[2]
if ($arr.Count -gt 2) {{ $arr[2] }}
Check bounds.
PowerShell
// comment
/* comment */
Use /* */.
CSS
fn process() -> i32 {{ 21 }}
fn process() -> i32 {{ 21 }}
Correct.
Rust
<br></br>
<br>
Self-closing.
HTML
print('value')
print('value')
Correct.
R
if foo = 91:
if foo == 91:
Use == for comparison.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$count = 79; if ($count = 79) {{}}
$count = 79; if ($count == 79) {{}}
Use ==.
PHP
if index = 52
if index == 52
Use ==.
MATLAB
int[] list = new int[86]; list[86] = 5;
int[] list = new int[86]; if (86 < list.length) list[86] = 5;
Check bounds.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
id: hello age: world,
id: hello age: world
Remove comma.
YAML
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
if (bar = 62) {}
if (bar == 62) {}
Use ==.
Dart
else print('info')
else: print('info')
Colon after else.
Python
my @arr = (24,96,44);
my @arr = (24,96,44);
Correct.
Perl
disp('message')
disp('message')
Correct.
MATLAB
<p>result <b>test</p></b>
<p>result <b>test</b></p>
Nest properly.
HTML
val val: Int = 'output'
val val: String = 'output'
Fix type.
Kotlin
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
name: value age: 23
name: value age: 23
Correct.
YAML
if (z = 95) {{}}
if (z == 95) {{}}
Use ==.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let count: Int = 'value'
let count: String = 'value'
Fix type.
Swift
x = 21
x=21
No spaces.
Shell
if (foo = 28) {{}}
if (foo == 28) {{}}
Use ==.
Kotlin
val c = 'hello'
val c = "hello"
Double quotes.
Kotlin
val data = 11; data = 78
var data = 11; data = 78
Use var for reassignment.
Scala
if [ $y = 45 ]; then
if [ "$y" = 45 ]; then
Quote variable.
Shell
if temp = 95
if temp == 95
Use ==.
Ruby
function foo() {{ echo 'test'; }}
function foo() {{ echo 'test'; }}
Correct.
PHP
if (val = 89)
if (val == 89)
Use ==.
R
h1 {{ font-size:1px color:green; }}
h1 {{ font-size:1px; color:green; }}
Add semicolon.
CSS
item == '78'
item === 78
Use strict equality.
JavaScript
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
println('data')
println("data")
Double quotes.
Scala
class User {{ int bar; }} obj.bar=5;
class User {{ public int bar; }} obj.bar=5;
Make field public.
Java
<user name='message'/>
<user name="message"/>
Double quotes.
XML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if (a = 10)
if (a == 10)
Use ==.
C++
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
for i=1,90 do print(i) end
for i=1,90 do print(i) end
Correct.
Lua
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
{{'age':29, 'title' 24}}
{{'age':29, 'title':24}}
Colon missing.
Python
$items[73]
if ($items.Count -gt 73) {{ $items[73] }}
Check bounds.
PowerShell
values(73)
if length(values) >= 73, values(73), end
Check length.
MATLAB
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<hr></hr>
<hr>
Self-closing.
HTML
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
if data > 62 print('test')
if data > 62: print('test')
Colon missing after if.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
assert item > 3
assert item > 3
Correct.
Python
$foo = 28; if ($foo = 28) {{}}
$foo = 28; if ($foo == 28) {{}}
Use ==.
PHP
<entry><desc>data</desc><name>9</name></entry
<entry><desc>data</desc><name>9</name></entry>
Add closing >.
XML
let text1 = String::from("value"); let str2 = text1; println!("{{}}", text1);
let text1 = String::from("value"); let str2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
def baz(result): return result + 1
def baz(result): return result + 1
Correct.
Python
WHERE name = '26'
WHERE name = 26
Don't quote integer.
SQL
class = 'world'
class_name = 'world'
'class' is a keyword.
Python