wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
match val {{ 1 => {{}} }}
match val {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if count = 99:
if count == 99:
Use == for comparison.
Python
echo result world
echo 'result world'
Quote to prevent splitting.
Shell
if ($c = 90) {{}}
if ($c -eq 90) {{}}
Use -eq.
PowerShell
class Person {{ int a; }};
class Person {{ public: int a; }};
Make public.
C++
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
val y: Int = 'value'
val y: String = 'value'
Fix type.
Kotlin
if bar = 95 {{}}
if bar == 95 {{}}
Use ==.
Swift
c = 94
c=94
No spaces.
Shell
if ($item = 3)
if ($item == 3)
Use ==.
Perl
z > 58 & x < 71
z > 58 and x < 71
Use 'and' not '&'.
Python
'info' + 31
'info' + str(31)
Can't add int to string.
Python
let list=vec![35,40,23]; let first=&list[0]; list.push(67);
let mut list=vec![35,40,23]; let first=list[0]; list.push(67);
Copy instead of reference.
Rust
class = 'info'
class_name = 'info'
'class' is a keyword.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(14);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(14, () => console.log('listening'));
Add callback.
Node.js
let count: Int = 'data'
let count: String = 'data'
Fix type.
Swift
if [ $val = 32 ]; then
if [ "$val" = 32 ]; then
Quote variable.
Shell
def baz(): print('data')
def baz(): print('data')
Indent function body.
Python
$list[87]
if ($list.Count -gt 87) {{ $list[87] }}
Check bounds.
PowerShell
[99, 35, 80
[99, 35, 80]
Close bracket.
Ruby
function handle(): void {{ return 30; }}
function handle(): number {{ return 30; }}
Return type mismatch.
TypeScript
<hr></hr>
<hr>
Self-closing.
HTML
const obj:Person = {{name:'data'}};
const obj:Person = {{name:'data', age:78}};
Add missing property.
TypeScript
process
process()
Add parentheses.
Kotlin
$items[85] = 5;
if (isset($items[85])) $items[85] = 5;
Check existence.
PHP
arr[53]
if (arr.indices.contains(53)) arr[53]
Check index.
Kotlin
val z = 'hello'
val z = "hello"
Double quotes.
Kotlin
$temp = 57; if ($temp = 57) {{}}
$temp = 57; if ($temp == 57) {{}}
Use ==.
PHP
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
print 'data'
print('data')
print needs parentheses.
Python
// comment
/* comment */
Use /* */.
CSS
for num in range(92) print(num)
for num in range(92): print(num)
Colon after for.
Python
<entry name='test'/>
<entry name="test"/>
Double quotes.
XML
{{"name":"output" "id":37}}
{{"name":"output", "id":37}}
Add comma.
JSON
cin >> a;
int a; cin >> a;
Declare variable.
C++
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
data[56]
if data.indices.contains(56) {{ data[56] }}
Check index.
Swift
print 'message'
print 'message';
Add semicolon.
Perl
disp('result')
disp('result')
Correct.
MATLAB
let foo: number = 'test';
let foo: string = 'test';
Fix type.
TypeScript
function bar() {{ return {{key:'test'}} }}
function bar() {{ return {{key:'test'}}; }}
Return object on same line.
JavaScript
os.sqrt(21)
import os os.sqrt(21)
Import module first.
Python
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
<note><desc>message</desc><desc>9</desc></note
<note><desc>message</desc><desc>9</desc></note>
Add closing >.
XML
y == '96'
y === 96
Use strict equality.
JavaScript
fn foo() -> i32 {{ 72 }}
fn foo() -> i32 {{ 72 }}
Correct.
Rust
h1 {{ font-size:14px color:red; }}
h1 {{ font-size:14px; color:red; }}
Add semicolon.
CSS
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
values.forEach(function(count) {{ console.log(count); }})
values.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
console.log('hello'
console.log('hello')
Close parenthesis.
JavaScript
String temp = 'message';
String temp = "message";
Double quotes.
Java
Post.save();
Post.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
void baz(); int main(){{baz();}}
void baz(); // prototype int main(){{baz();}}
Declare before use.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
SELECT id email FROM products;
SELECT id, email FROM products;
Add comma.
SQL
let item = 19;
let item = 19;
Correct.
JavaScript
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
z = value
z = 'value'
Quote strings.
Python
title: value name: hello,
title: value name: hello
Remove comma.
YAML
12foo = 10
foo12 = 10
Variable cannot start with digit.
Python
def bar(index): return index + 1
def bar(index): return index + 1
Correct.
Python
with open('log.txt') as f: data = f.read()
with open('log.txt') as f: data = f.read()
Correct.
Python
<?php // code ?>
<?php // code ?>
Correct.
PHP
WHERE name = '13'
WHERE name = 13
Don't quote integer.
SQL
if b = 6
if b == 6
Use ==.
Go
UPDATE products SET id='output' WHERE status=52
UPDATE products SET id='output' WHERE status=52;
Add semicolon.
SQL
let str1 = String::from("data"); let s2 = str1; println!("{{}}", str1);
let str1 = String::from("data"); let s2 = str1.clone(); println!("{{}}", str1);
Clone to avoid move.
Rust
function render(index:string){{return index;}} render(60);
function render(index:string){{return index;}} render('data');
Pass correct type.
TypeScript
DELETE FROM products WHERE name=7
DELETE FROM products WHERE name=7;
Add semicolon.
SQL
INSERT INTO products VALUES ('value',95)
INSERT INTO products (age, status) VALUES ('value',95);
Specify columns.
SQL
class User {{ int result; }} obj.result=5;
class User {{ public int result; }} obj.result=5;
Make field public.
Java
int data[48]; data[48]=5;
int data[48]; if(48<48){{}} else data[48]=5;
Bounds check.
C++
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
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
assert a > 29
assert a > 29
Correct.
Python
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
my @arr = (82,88,23);
my @arr = (82,88,23);
Correct.
Perl
let index: i32 = "test";
let index: &str = "test";
Type mismatch.
Rust
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
def handle puts 'world' end
def handle puts 'world' end
Correct.
Ruby
let result = 'world'
let result = "world"
Double quotes.
Swift
int[] arr = new int[42]; arr[42] = 5;
int[] arr = new int[42]; if (42 < arr.length) arr[42] = 5;
Check bounds.
Java
else print('hello')
else: print('hello')
Colon after else.
Python
if (index = 81) {{}}
if (index === 81) {{}}
Use === for equality.
JavaScript
<br></br>
<br>
Self-closing.
HTML
echo 'hello'
echo 'hello';
Add semicolon.
PHP
{{'value':59, 'value' 47}}
{{'value':59, 'value':47}}
Colon missing.
Python
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
test
test()
Add parentheses.
Swift
<p>output <b>world</p></b>
<p>output <b>world</b></p>
Nest properly.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
list[71]
if (length(list) >= 71) list[71]
Check length.
R
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for (b in values)
for (b of values)
for...in iterates keys.
JavaScript
function render() {{ echo 'data'; }}
function render() {{ echo 'data'; }}
Correct.
PHP