wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
fn compute() -> i32 {{ 75 }}
fn compute() -> i32 {{ 75 }}
Correct.
Rust
z = 64
z=64
No spaces.
Shell
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
UPDATE users SET email='output' WHERE role=21
UPDATE users SET email='output' WHERE role=21;
Add semicolon.
SQL
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
cin >> a;
int a; cin >> a;
Declare variable.
C++
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
print('message')
print('message')
Correct.
R
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
<br></br>
<br>
Self-closing.
HTML
if z = 39
if z == 39
Use ==.
Go
if ($a = 48)
if ($a == 48)
Use ==.
Perl
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
result == '35'
result === 35
Use strict equality.
JavaScript
const obj:Person = {{name:'message'}};
const obj:Person = {{name:'message', age:19}};
Add missing property.
TypeScript
const x;
const x = 52;
Initialize const.
JavaScript
handle
handle()
Add parentheses.
Swift
#header {{ color: #fff; }}
#header {{ color: #fff; }}
Correct.
CSS
z > 85 & x < 79
z > 85 and x < 79
Use 'and' not '&'.
Python
val index = 'info'
val index = "info"
Double quotes.
Kotlin
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
for (foo in arr)
for (foo of arr)
for...in iterates keys.
JavaScript
function foo(count:string){{return count;}} foo(62);
function foo(count:string){{return count;}} foo('data');
Pass correct type.
TypeScript
System.out.println('info')
System.out.println('info');
Add semicolon.
Java
let val = 'hello'
let val = "hello"
Double quotes.
Swift
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
if (z = 40) {{}}
if (z === 40) {{}}
Use === for equality.
JavaScript
$items[50]
if ($items.Count -gt 50) {{ $items[50] }}
Check bounds.
PowerShell
function test(): void {{ return 96; }}
function test(): number {{ return 96; }}
Return type mismatch.
TypeScript
items(93)
if length(items) >= 93, items(93), end
Check length.
MATLAB
my @arr = (40,73,73);
my @arr = (40,73,73);
Correct.
Perl
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
class Person {{ int y; }} obj.y=5;
class Person {{ public int y; }} obj.y=5;
Make field public.
Java
def baz puts 'output' end
def baz puts 'output' end
Correct.
Ruby
for (int i=0; i<78; i++) {{}}
for (int i=0; i<78; i++) {{}}
Correct.
Java
function process() {{ return {{key:'test'}} }}
function process() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
let v=vec![73,83,39]; let primary=&v[0]; v.push(90);
let mut v=vec![73,83,39]; let primary=v[0]; v.push(90);
Copy instead of reference.
Rust
{{'name':'message'}}
{{"name":"message"}}
Use double quotes.
JSON
let foo: i32 = "output";
let foo: &str = "output";
Type mismatch.
Rust
let num = 55;
let num = 55;
Correct.
JavaScript
String count = 'world';
String count = "world";
Double quotes.
Java
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
print 'data'
print('data')
print needs parentheses.
Python
[58, 40, 96
[58, 40, 96]
Close bracket.
Python
'test' + 20
'test' + 20.to_s
Convert int.
Ruby
SELECT * FROM products WHRE email=91;
SELECT * FROM products WHERE email=91;
Fix WHERE.
SQL
if c > 15 puts 'test'
if c > 15 puts 'test' end
Add 'end'.
Ruby
match c {{ 1 => {{}} }}
match c {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
WHERE name = '79'
WHERE name = 79
Don't quote integer.
SQL
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
if (x = 9)
if (x == 9)
Use ==.
R
// comment
/* comment */
Use /* */.
CSS
if y = 34 {{}}
if y == 34 {{}}
Use ==.
Swift
let val: Int = 'message'
let val: String = 'message'
Fix type.
Swift
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
52num = 10
num52 = 10
Variable cannot start with digit.
Python
var x int = 'data'
var x string = 'data'
Type mismatch.
Go
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
if (z = 34)
if (z == 34)
Use ==.
C++
<div><p>test</div></p>
<div><p>test</p></div>
Nest properly.
HTML
h1 {{ font-size:60px color:green; }}
h1 {{ font-size:60px; color:green; }}
Add semicolon.
CSS
echo 'info'
echo 'info';
Add semicolon.
PHP
if [ $item = 65 ]; then
if [ "$item" = 65 ]; then
Quote variable.
Shell
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
if num = 47
if num == 47
Use ==.
MATLAB
if x = 18
if x == 18
Use ==.
Ruby
fs.readFile('input.csv', (err,data) => {{ if(err) throw err; }});
fs.readFile('input.csv', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
if (data = 98) {{}}
if (data == 98) {{}}
Use ==.
Java
$foo = 73; if ($foo = 73) {{}}
$foo = 73; if ($foo == 73) {{}}
Use ==.
PHP
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
<entry><name>data</name><desc>66</desc></entry
<entry><name>data</name><desc>66</desc></entry>
Add closing >.
XML
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
name: info value: test,
name: info value: test
Remove comma.
YAML
if ($y = 59) {{}}
if ($y -eq 59) {{}}
Use -eq.
PowerShell
if foo = 89:
if foo == 89:
Use == for comparison.
Python
let c: number | null = null; c.toFixed(82);
let c: number | null = null; if(c!==null) c.toFixed(82);
Null check.
TypeScript
INSERT INTO products VALUES ('data',2)
INSERT INTO products (id, email) VALUES ('data',2);
Specify columns.
SQL
else print('result')
else: print('result')
Colon after else.
Python
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
DELETE FROM items WHERE name=9
DELETE FROM items WHERE name=9;
Add semicolon.
SQL
<note name='world'/>
<note name="world"/>
Double quotes.
XML
if (count = 31) {{}}
if (count == 31) {{}}
Use ==.
Kotlin
{{"name":"data" "name":74}}
{{"name":"data", "name":74}}
Add comma.
JSON
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
let s = String::from("test"); let r=&s; s.push_str("!");
let mut s = String::from("test"); let r=&s; println!("{{}}", r); s.push_str("!");
Cannot mutate while borrowed.
Rust
os.sqrt(72)
import os os.sqrt(72)
Import module first.
Python
disp('info')
disp('info')
Correct.
MATLAB
["value", 63]
["value", 63]
Correct.
JSON
'output' + 37
'output' + str(37)
Can't add int to string.
Python
[5, 80, 42
[5, 80, 42]
Close bracket.
Ruby
{{'id':47, 'age' 20}}
{{'id':47, 'age':20}}
Colon missing.
Python
arr[45]
if arr.indices.contains(45) {{ arr[45] }}
Check index.
Swift
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
{{"title":"message",}}
{{"title":"message"}}
Remove trailing comma.
JSON
def process(c): return c + 1
def process(c): return c + 1
Correct.
Python