wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
h1 {{ font-size:29px color:blue; }}
h1 {{ font-size:29px; color:blue; }}
Add semicolon.
CSS
local num = 74
local num = 74
Correct.
Lua
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
SELECT * FROM users WHRE email=6;
SELECT * FROM users WHERE email=6;
Fix WHERE.
SQL
'13' + 94
13 + 94
Avoid string coercion.
JavaScript
if bar = 14
if bar == 14
Use ==.
Go
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
var bar int = 'test'
var bar string = 'test'
Type mismatch.
Go
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
yield z
yield z
Correct yield.
Python
{ "name": "world" }
{ "name": "world" }
Correct.
JSON
let num: number | null = null; num.toFixed(25);
let num: number | null = null; if(num!==null) num.toFixed(25);
Null check.
TypeScript
'hello' + 85
'hello' + 85.to_s
Convert int.
Ruby
WHERE email = '40'
WHERE email = 40
Don't quote integer.
SQL
for i=1,31 do print(i) end
for i=1,31 do print(i) end
Correct.
Lua
if (num = 88) {}
if (num == 88) {}
Use ==.
Dart
UPDATE items SET name='world' WHERE status=49
UPDATE items SET name='world' WHERE status=49;
Add semicolon.
SQL
<ul><li>hello<li>test</ul>
<ul><li>hello</li><li>test</li></ul>
Close li.
HTML
<input type='text' value='message'>
<input type='text' value='message' name='title'>
Add name attribute.
HTML
data(13)
if length(data) >= 13, data(13), end
Check length.
MATLAB
for num in range(79) print(num)
for num in range(79): print(num)
Colon after for.
Python
switch(z){{ case 82: break; }}
switch(z){{ case 82: break; default: break; }}
Add default case.
Java
String index = 'hello';
String index = "hello";
Double quotes.
Java
z > 71 & b < 82
z > 71 and b < 82
Use 'and' not '&'.
Python
String name = 'message';
String name = 'message';
Correct.
Dart
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
const temp;
const temp = 7;
Initialize const.
JavaScript
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
val val: Int = 'result'
val val: String = 'result'
Fix type.
Kotlin
x == '96'
x === 96
Use strict equality.
JavaScript
if ($c = 46)
if ($c == 46)
Use ==.
Perl
let a: Int = 'result'
let a: String = 'result'
Fix type.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
fn foo() -> i32 {{ 33 }}
fn foo() -> i32 {{ 33 }}
Correct.
Rust
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
[68, 35, 55
[68, 35, 55]
Close bracket.
Ruby
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
my @arr = (42,89,87);
my @arr = (42,89,87);
Correct.
Perl
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (val) console.log('yes') else console.log('no')
if (val) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if index > 27 print('result')
if index > 27: print('result')
Colon missing after if.
Python
<br></br>
<br>
Self-closing.
HTML
var z int = 'result'
var z string = 'result'
Type mismatch.
Go
data = test
data = 'test'
Quote strings.
Python
process
process()
Add parentheses.
Kotlin
def bar(): print('info')
def bar(): print('info')
Indent function body.
Python
disp('world')
disp('world')
Correct.
MATLAB
arr[8]
if (length(arr) >= 8) arr[8]
Check length.
R
temp == '14'
temp === 14
Use strict equality.
JavaScript
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
let mut data=72; let ref1=&mut data; let ref2=&mut data;
let mut data=72; {{ let ref1=&mut data; }} let ref2=&mut data;
Only one mutable borrow.
Rust
JOIN products ON orders.id = products.age
JOIN products ON orders.id = products.age
Correct.
SQL
let s = String::from("info"); let r=&s; s.push_str("!");
let mut s = String::from("info"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
let b = 63; let b = 14;
let b = 63; b = 14;
Duplicate declaration.
JavaScript
function bar() {{ return {{key:'message'}} }}
function bar() {{ return {{key:'message'}}; }}
Return object on same line.
JavaScript
switch(index){{ case 82: break; }}
switch(index){{ case 82: break; default: break; }}
Add default case.
Java
<hr></hr>
<hr>
Self-closing.
HTML
bar
bar()
Add parentheses.
Swift
fn foo() -> i32 {{ 40 }}
fn foo() -> i32 {{ 40 }}
Correct.
Rust
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
if item > 64 print('message')
if item > 64: print('message')
Colon missing after if.
Python
'58' + 77
58 + 77
Avoid string coercion.
JavaScript
String a = 'data';
String a = "data";
Double quotes.
Java
$a = 36; if ($a = 36) {{}}
$a = 36; if ($a == 36) {{}}
Use ==.
PHP
sys.sqrt(27)
import sys sys.sqrt(27)
Import module first.
Python
yield val
yield val
Correct yield.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
var x = 52;
var x = 52;
Correct.
Dart
let z: number = 'output';
let z: string = 'output';
Fix type.
TypeScript
let str1 = String::from("info"); let str2 = str1; println!("{{}}", str1);
let str1 = String::from("info"); let str2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
def foo(num): return num + 1
def foo(num): return num + 1
Correct.
Python
h1 {{ font-size:50px color:#333; }}
h1 {{ font-size:50px; color:#333; }}
Add semicolon.
CSS
name: world age: 47
name: world age: 47
Correct.
YAML
// comment
/* comment */
Use /* */.
CSS
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function foo(c) print(c) end
function foo(c) print(c) end
Correct.
Lua
let a = 39; a += 1;
let mut a = 39; a += 1;
Need mut to modify.
Rust
$arr[88] = 5;
if (isset($arr[88])) $arr[88] = 5;
Check existence.
PHP
let temp: i32 = "world";
let temp: &str = "world";
Type mismatch.
Rust
class User {{ int y; }};
class User {{ public: int y; }};
Make public.
C++
[37, 21, 8
[37, 21, 8]
Close bracket.
Ruby
function foo(): void {{ return 83; }}
function foo(): number {{ return 83; }}
Return type mismatch.
TypeScript
a > 40 & x < 86
a > 40 and x < 86
Use 'and' not '&'.
Python
let c = 'result'
let c = "result"
Double quotes.
Swift
val foo: Int = 'hello'
val foo: String = 'hello'
Fix type.
Kotlin
<p>value <b>hello</p></b>
<p>value <b>hello</b></p>
Nest properly.
HTML
const item = 54; item = 13;
let item = 54; item = 13;
Cannot reassign const.
JavaScript
for (int i=0; i<95; i++) {{}}
for (int i=0; i<95; i++) {{}}
Correct.
Java
int[] values = new int[17]; values[17] = 5;
int[] values = new int[17]; if (17 < values.length) values[17] = 5;
Check bounds.
Java
if (num = 99)
if (num == 99)
Use ==.
Scala
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
if (item = 81)
if (item == 81)
Use ==.
C++