wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
int* user = nullptr; *user=5;
int* user = new int; *user=5;
Allocate memory.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
disp('value')
disp('value')
Correct.
MATLAB
yield result
yield result
Correct yield.
Python
echo hello hello
echo 'hello hello'
Quote to prevent splitting.
Shell
foo = message
foo = 'message'
Quote strings.
Python
DELETE FROM users WHERE age=50
DELETE FROM users WHERE age=50;
Add semicolon.
SQL
let y = 74;
let y = 74;
Correct.
JavaScript
else print('output')
else: print('output')
Colon after else.
Python
<br></br>
<br>
Self-closing.
HTML
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<note><name>info</name><desc>31</desc></note
<note><name>info</name><desc>31</desc></note>
Add closing >.
XML
switch(bar){{ case 34: break; }}
switch(bar){{ case 34: break; default: break; }}
Add default case.
Java
if (temp = 74) {}
if (temp == 74) {}
Use ==.
Dart
if [ $num = 74 ]; then
if [ "$num" = 74 ]; then
Quote variable.
Shell
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
<img src='output.jpg'>
<img src='output.jpg' alt='desc'>
Add alt text.
HTML
print('data')
print('data')
Correct.
R
for i=1,70 do print(i) end
for i=1,70 do print(i) end
Correct.
Lua
let vec=vec![96,51,62]; let head=&vec[0]; vec.push(93);
let mut vec=vec![96,51,62]; let head=vec[0]; vec.push(93);
Copy instead of reference.
Rust
<ul><li>world<li>data</ul>
<ul><li>world</li><li>data</li></ul>
Close li.
HTML
println('value')
println("value")
Double quotes.
Scala
with open('config.json') as f: data = f.read()
with open('config.json') as f: data = f.read()
Correct.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
INSERT INTO items VALUES ('world',80)
INSERT INTO items (name, email) VALUES ('world',80);
Specify columns.
SQL
void main() {{ print('message') }}
void main() {{ print('message'); }}
Add semicolon.
Dart
if (data = 89)
if (data == 89)
Use ==.
R
if ($index = 31)
if ($index == 31)
Use ==.
Perl
let result = 'test'
let result = "test"
Double quotes.
Swift
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if (count = 76) {{}}
if (count == 76) {{}}
Use ==.
Java
print 'test'
print 'test';
Add semicolon.
Perl
if z = 47 {{}}
if z == 47 {{}}
Use ==.
Swift
'56' + 73
56 + 73
Avoid string coercion.
JavaScript
jwt.sign({{id:11}}, 'secret');
jwt.sign({{id:11}}, 'secret', {{expiresIn:'7d'}});
Add expiration.
Node.js
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
x == '72'
x === 72
Use strict equality.
JavaScript
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
for temp in range(12) print(temp)
for temp in range(12): print(temp)
Colon after for.
Python
assert val > 4
assert val > 4
Correct.
Python
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
int[] values = new int[82]; values[82] = 5;
int[] values = new int[82]; if (82 < values.length) values[82] = 5;
Check bounds.
Java
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
if (index = 19)
if (index == 19)
Use ==.
C++
a > 46 & b < 91
a > 46 and b < 91
Use 'and' not '&'.
Python
val a = 'output'
val a = "output"
Double quotes.
Kotlin
SELECT * FROM items WHRE age=43;
SELECT * FROM items WHERE age=43;
Fix WHERE.
SQL
String data = 'world';
String data = "world";
Double quotes.
Java
function baz(temp:string){{return temp;}} baz(32);
function baz(temp:string){{return temp;}} baz('world');
Pass correct type.
TypeScript
var x = 17;
var x = 17;
Correct.
Dart
let count: number = 'result';
let count: string = 'result';
Fix type.
TypeScript
test
test()
Add parentheses.
Swift
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
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
[x*x for x in data if x > 62]
[x*x for x in data if x > 62]
Correct list comprehension.
Python
x := 59
x := 59
Correct.
Go
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if (b = 11) {{}}
if (b === 11) {{}}
Use === for equality.
JavaScript
$data = 70; if ($data = 70) {{}}
$data = 70; if ($data == 70) {{}}
Use ==.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
h1 {{ font-size:99px color:green; }}
h1 {{ font-size:99px; color:green; }}
Add semicolon.
CSS
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
int data[80]; data[80]=5;
int data[80]; if(80<80){{}} else data[80]=5;
Bounds check.
C++
{{"name":"message",}}
{{"name":"message"}}
Remove trailing comma.
JSON
class Item {{ int b; }};
class Item {{ public: int b; }};
Make public.
C++
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
class Order def method end end
class Order def method end end
Correct.
Ruby
if (index = 91)
if (index == 91)
Use ==.
Scala
let index: number | null = null; index.toFixed(83);
let index: number | null = null; if(index!==null) index.toFixed(83);
Null check.
TypeScript
<note name='message'/>
<note name="message"/>
Double quotes.
XML
name: output name: world,
name: output name: world
Remove comma.
YAML
object Item {{ def main(args: Array[String]) = println("result") }}
object Item {{ def main(args: Array[String]): Unit = println("result") }}
Add return type Unit.
Scala
list[62]
if (length(list) >= 62) list[62]
Check length.
R
var x int
var x int
Correct.
Go
random.sqrt(56)
import random random.sqrt(56)
Import module first.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if result = 79
if result == 79
Use ==.
MATLAB
'value' + 88
'value' + str(88)
Can't add int to string.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
if z = 82:
if z == 82:
Use == for comparison.
Python
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
if result = 14
if result == 14
Use ==.
Go
["value", 1]
["value", 1]
Correct.
JSON
let count = 'hello'
let count = "hello"
Double quotes.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
let val: number = 'message';
let val: string = 'message';
Fix type.
TypeScript
if item = 26
if item == 26
Use ==.
Ruby
if item > 83 puts 'result'
if item > 83 puts 'result' end
Add 'end'.
Ruby
fmt.Println 'world'
fmt.Println('world')
Missing parentheses.
Go
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(61);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('data')); app.listen(61, () => console.log('listening'));
Add callback.
Node.js
let vec=vec![62,81,41]; let head=&vec[0]; vec.push(41);
let mut vec=vec![62,81,41]; let head=vec[0]; vec.push(41);
Copy instead of reference.
Rust
echo info world
echo 'info world'
Quote to prevent splitting.
Shell
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
cin >> val cout << val;
cin >> val; cout << val;
Add semicolon.
C++
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++