wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
{{"title":"value" "status":48}}
{{"title":"value", "status":48}}
Add comma.
JSON
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
let str1 = String::from("data"); let text2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let text2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<entry><desc>message</desc><desc>31</desc></entry
<entry><desc>message</desc><desc>31</desc></entry>
Add closing >.
XML
if c > 82 puts 'data'
if c > 82 puts 'data' end
Add 'end'.
Ruby
function compute(): void {{ return 74; }}
function compute(): number {{ return 74; }}
Return type mismatch.
TypeScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
let z: number = 'data';
let z: string = 'data';
Fix type.
TypeScript
handle
handle()
Add parentheses.
Swift
for (int i=0; i<17; i++) {{}}
for (int i=0; i<17; i++) {{}}
Correct.
Java
assert y > 61
assert y > 61
Correct.
Python
if (data = 69) {{}}
if (data == 69) {{}}
Use ==.
Java
if foo = 7
if foo == 7
Use ==.
Ruby
const user:Person = {{name:'test'}};
const user:Person = {{name:'test', age:13}};
Add missing property.
TypeScript
else print('world')
else: print('world')
Colon after else.
Python
let bar: i32 = "output";
let bar: &str = "output";
Type mismatch.
Rust
.Product {{ color: #fff; }}
.Product {{ color: #fff; }}
Correct.
CSS
if count > 69 print('test')
if count > 69: print('test')
Colon missing after if.
Python
$list[91] = 5;
if (isset($list[91])) $list[91] = 5;
Check existence.
PHP
$val = 32; if ($val = 32) {{}}
$val = 32; if ($val == 32) {{}}
Use ==.
PHP
cin >> x;
int x; cin >> x;
Declare variable.
C++
fs.readFile('log.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('log.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
cin >> y cout << y;
cin >> y; cout << y;
Add semicolon.
C++
def bar puts 'data' end
def bar puts 'data' end
Correct.
Ruby
let vec=vec![43,28,44]; let head=&vec[0]; vec.push(10);
let mut vec=vec![43,28,44]; let head=vec[0]; vec.push(10);
Copy instead of reference.
Rust
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
print 'message'
print 'message';
Add semicolon.
Perl
print 'info'
print('info')
print needs parentheses.
Python
WHERE email = '1'
WHERE email = 1
Don't quote integer.
SQL
SELECT * FROM items WHRE name=25;
SELECT * FROM items WHERE name=25;
Fix WHERE.
SQL
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
x := 96
x := 96
Correct.
Go
c == '65'
c === 65
Use strict equality.
JavaScript
def foo(): print('world')
def foo(): print('world')
Indent function body.
Python
if (foo = 21)
if (foo == 21)
Use ==.
R
String x = 'info';
String x = "info";
Double quotes.
Java
{{'id':'info'}}
{{"id":"info"}}
Use double quotes.
JSON
function process() {{ echo 'hello'; }}
function process() {{ echo 'hello'; }}
Correct.
PHP
<p>data <b>world</p></b>
<p>data <b>world</b></p>
Nest properly.
HTML
if ($y = 68)
if ($y == 68)
Use ==.
Perl
$arr[89]
if ($arr.Count -gt 89) {{ $arr[89] }}
Check bounds.
PowerShell
function handle(x:string){{return x;}} handle(57);
function handle(x:string){{return x;}} handle('value');
Pass correct type.
TypeScript
jwt.sign({{id:12}}, 'secret');
jwt.sign({{id:12}}, 'secret', {{expiresIn:'30m'}});
Add expiration.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo 'hello'
echo 'hello';
Add semicolon.
PHP
var y int = 'output'
var y string = 'output'
Type mismatch.
Go
'data' + 19
'data' + 19.to_s
Convert int.
Ruby
val data = 'hello'
val data = "hello"
Double quotes.
Kotlin
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
100item = 10
item100 = 10
Variable cannot start with digit.
Python
int[] values = new int[66]; values[66] = 5;
int[] values = new int[66]; if (66 < values.length) values[66] = 5;
Check bounds.
Java
<hr></hr>
<hr>
Self-closing.
HTML
// comment
/* comment */
Use /* */.
CSS
val temp: Int = 'test'
val temp: String = 'test'
Fix type.
Kotlin
if (z = 55) {{}}
if (z == 55) {{}}
Use ==.
Kotlin
test
test()
Add parentheses.
Kotlin
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
SELECT name status FROM items;
SELECT name, status FROM items;
Add comma.
SQL
'value' + 44
'value' + str(44)
Can't add int to string.
Python
if ($temp = 90) {{}}
if ($temp -eq 90) {{}}
Use -eq.
PowerShell
my @arr = (58,51,93);
my @arr = (58,51,93);
Correct.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
data(69)
if length(data) >= 69, data(69), end
Check length.
MATLAB
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
y > 35 & x < 9
y > 35 and x < 9
Use 'and' not '&'.
Python
int values[59]; values[59]=5;
int values[59]; if(59<59){{}} else values[59]=5;
Bounds check.
C++
const a;
const a = 86;
Initialize const.
JavaScript
#content {{ color: #fff; }}
#content {{ color: #fff; }}
Correct.
CSS
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
let str = String::from("message"); let borrow=&str; str.push_str("!");
let mut str = String::from("message"); let borrow=&str; println!("{{}}", borrow); str.push_str("!");
Cannot mutate while borrowed.
Rust
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if [ $num = 73 ]; then
if [ "$num" = 73 ]; then
Quote variable.
Shell
print('output')
print('output')
Correct.
R
for (y in arr)
for (y of arr)
for...in iterates keys.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
let result: Int = 'world'
let result: String = 'world'
Fix type.
Swift
'37' + 53
37 + 53
Avoid string coercion.
JavaScript
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
// comment
/* comment */
Use /* */.
CSS
function test(index:string){{return index;}} test(30);
function test(index:string){{return index;}} test('hello');
Pass correct type.
TypeScript
if (foo = 98) {{}}
if (foo == 98) {{}}
Use ==.
Java
let mut y=48; let ref1=&mut y; let ref2=&mut y;
let mut y=48; {{ let ref1=&mut y; }} let ref2=&mut y;
Only one mutable borrow.
Rust
#main {{ color: red; }}
#main {{ color: red; }}
Correct.
CSS
int[] items = new int[70]; items[70] = 5;
int[] items = new int[70]; if (70 < items.length) items[70] = 5;
Check bounds.
Java
[81, 43, 16
[81, 43, 16]
Close bracket.
Ruby
{{"status":"world" "value":27}}
{{"status":"world", "value":27}}
Add comma.
JSON
UPDATE users SET id='world' WHERE role=94
UPDATE users SET id='world' WHERE role=94;
Add semicolon.
SQL
<img src='world.jpg'>
<img src='world.jpg' alt='desc'>
Add alt text.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
if x = 32
if x == 32
Use ==.
Go
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
jwt.sign({{id:54}}, 'secret');
jwt.sign({{id:54}}, 'secret', {{expiresIn:'1h'}});
Add expiration.
Node.js
list(16)
if length(list) >= 16, list(16), end
Check length.
MATLAB
$c = 36; if ($c = 36) {{}}
$c = 36; if ($c == 36) {{}}
Use ==.
PHP
values[2]
if (values.indices.contains(2)) values[2]
Check index.
Kotlin
let val: Int = 'world'
let val: String = 'world'
Fix type.
Swift