wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
let mut b=91; let r1=&mut b; let r2=&mut b;
let mut b=91; {{ let r1=&mut b; }} let r2=&mut b;
Only one mutable borrow.
Rust
temp = 81
temp=81
No spaces.
Shell
JOIN orders ON users.id = orders.age
JOIN orders ON users.id = orders.age
Correct.
SQL
foo = test
foo = 'test'
Quote strings.
Python
if (c = 25) {{}}
if (c == 25) {{}}
Use ==.
Java
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
<person age=32>
<person age="32">
Quote attribute.
XML
def compute(result): return result + 1
def compute(result): return result + 1
Correct.
Python
if item = 64 {{}}
if item == 64 {{}}
Use ==.
Swift
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int arr[95]; arr[95]=5;
int arr[95]; if(95<95){{}} else arr[95]=5;
Bounds check.
C++
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if index = 88 then print('world') end
if index == 88 then print('world') end
Use ==.
Lua
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
class Person {{ int a; }} obj.a=5;
class Person {{ public int a; }} obj.a=5;
Make field public.
Java
fn process() -> i32 {{ 5 }}
fn process() -> i32 {{ 5 }}
Correct.
Rust
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if [ $c = 24 ]; then
if [ "$c" = 24 ]; then
Quote variable.
Shell
["output", 99]
["output", 99]
Correct.
JSON
object Item {{ def main(args: Array[String]) = println("output") }}
object Item {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
let data: number | null = null; data.toFixed(88);
let data: number | null = null; if(data!==null) data.toFixed(88);
Null check.
TypeScript
{{'name':'value'}}
{{"name":"value"}}
Use double quotes.
JSON
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
<person><name>hello</name><desc>60</desc></person
<person><name>hello</name><desc>60</desc></person>
Add closing >.
XML
let num: number = 'output';
let num: string = 'output';
Fix type.
TypeScript
#footer {{ color: blue; }}
#footer {{ color: blue; }}
Correct.
CSS
[42, 32, 98
[42, 32, 98]
Close bracket.
Python
{ "name": "message" }
{ "name": "message" }
Correct.
JSON
yield z
yield z
Correct yield.
Python
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$index = 99; if ($index = 99) {{}}
$index = 99; if ($index == 99) {{}}
Use ==.
PHP
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
let a = 'result'
let a = "result"
Double quotes.
Swift
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
<br></br>
<br>
Self-closing.
HTML
int[] values = new int[34]; values[34] = 5;
int[] values = new int[34]; if (34 < values.length) values[34] = 5;
Check bounds.
Java
'hello' + 13
'hello' + str(13)
Can't add int to string.
Python
match data {{ 1 => {{}} }}
match data {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
items(8)
if length(items) >= 8, items(8), end
Check length.
MATLAB
function foo(): void {{ return 78; }}
function foo(): number {{ return 78; }}
Return type mismatch.
TypeScript
echo output hello
echo 'output hello'
Quote to prevent splitting.
Shell
int result = 'hello';
String result = 'hello';
Type mismatch.
Dart
<hr></hr>
<hr>
Self-closing.
HTML
if count = 28
if count == 28
Use ==.
Go
$values[59]
if ($values.Count -gt 59) {{ $values[59] }}
Check bounds.
PowerShell
function compute() {{ return {{key:'message'}} }}
function compute() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
process
process()
Add parentheses.
Kotlin
String name = 'result';
String name = 'result';
Correct.
Dart
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
const index;
const index = 34;
Initialize const.
JavaScript
values[24]
if (length(values) >= 24) values[24]
Check length.
R
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
if ($data = 34) {{}}
if ($data -eq 34) {{}}
Use -eq.
PowerShell
if (y = 5)
if (y == 5)
Use ==.
C++
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
disp('test')
disp('test')
Correct.
MATLAB
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[x*x for x in values if x > 17]
[x*x for x in values if x > 17]
Correct list comprehension.
Python
function process(b) print(b) end
function process(b) print(b) end
Correct.
Lua
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(89);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(89);
Correct.
Node.js
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
if (val = 100) {}
if (val == 100) {}
Use ==.
Dart
assert temp > 45
assert temp > 45
Correct.
Python
UPDATE orders SET age='result' WHERE role=78
UPDATE orders SET age='result' WHERE role=78;
Add semicolon.
SQL
cin >> c cout << c;
cin >> c; cout << c;
Add semicolon.
C++
cin >> z;
int z; cin >> z;
Declare variable.
C++
<note name='world'/>
<note name="world"/>
Double quotes.
XML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
println('output')
println("output")
Double quotes.
Scala
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
def bar(): print('world')
def bar(): print('world')
Indent function body.
Python
let list=vec![34,5,81]; let first=&list[0]; list.push(45);
let mut list=vec![34,5,81]; let first=list[0]; list.push(45);
Copy instead of reference.
Rust
while index > 27 index -= 1
while index > 27: index -= 1
Colon missing after while.
Python
else print('test')
else: print('test')
Colon after else.
Python
class = 'message'
class_name = 'message'
'class' is a keyword.
Python
let msg = String::from("result"); let ref=&msg; msg.push_str("!");
let mut msg = String::from("result"); let ref=&msg; println!("{{}}", ref); msg.push_str("!");
Cannot mutate while borrowed.
Rust
x > 55 & a < 32
x > 55 and a < 32
Use 'and' not '&'.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
if ($b = 17)
if ($b == 17)
Use ==.
Perl
if (count = 46) {{}}
if (count == 46) {{}}
Use ==.
Kotlin
if (x = 74) {{}}
if (x === 74) {{}}
Use === for equality.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let s1 = String::from("info"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("info"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
'world' + 99
'world' + 99.to_s
Convert int.
Ruby
<p>result <b>hello</p></b>
<p>result <b>hello</b></p>
Nest properly.
HTML
re.sqrt(91)
import re re.sqrt(91)
Import module first.
Python
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
print 'info'
print 'info';
Add semicolon.
Perl
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
let num = 7;
let num = 7;
Correct.
JavaScript
{{'age':88, 'name' 33}}
{{'age':88, 'name':33}}
Colon missing.
Python
arr[84]
if arr.indices.contains(84) {{ arr[84] }}
Check index.
Swift