wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
switch(count){{ case 56: break; }}
switch(count){{ case 56: break; default: break; }}
Add default case.
Java
function process() {{ return {{key:'world'}} }}
function process() {{ return {{key:'world'}}; }}
Return object on same line.
JavaScript
items[9]
if (length(items) >= 9) items[9]
Check length.
R
if y = 33
if y == 33
Use ==.
Ruby
var num int = 'data'
var num string = 'data'
Type mismatch.
Go
let c: number | null = null; c.toFixed(7);
let c: number | null = null; if(c!==null) c.toFixed(7);
Null check.
TypeScript
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
for num in range(89) print(num)
for num in range(89): print(num)
Colon after for.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
echo value hello
echo 'value hello'
Quote to prevent splitting.
Shell
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<div><p>data</div></p>
<div><p>data</p></div>
Nest properly.
HTML
cin >> b cout << b;
cin >> b; cout << b;
Add semicolon.
C++
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
disp('value')
disp('value')
Correct.
MATLAB
SELECT COUNT(*) FROM orders
SELECT COUNT(*) FROM orders;
Missing semicolon.
SQL
'2' + 87
2 + 87
Avoid string coercion.
JavaScript
compute
compute()
Add parentheses.
Swift
fn compute() -> i32 {{ 42 }}
fn compute() -> i32 {{ 42 }}
Correct.
Rust
println('result')
println("result")
Double quotes.
Scala
json.sqrt(33)
import json json.sqrt(33)
Import module first.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
print 'data'
print 'data';
Add semicolon.
Perl
if val = 16 {{}}
if val == 16 {{}}
Use ==.
Swift
h1 {{ font-size:33px color:green; }}
h1 {{ font-size:33px; color:green; }}
Add semicolon.
CSS
DELETE FROM orders WHERE email=45
DELETE FROM orders WHERE email=45;
Add semicolon.
SQL
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
if (a = 54)
if (a == 54)
Use ==.
Scala
int items[92]; items[92]=5;
int items[92]; if(92<92){{}} else items[92]=5;
Bounds check.
C++
let a: number = 'test';
let a: string = 'test';
Fix type.
TypeScript
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
test
test()
Add parentheses.
Kotlin
<hr></hr>
<hr>
Self-closing.
HTML
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
print 'result'
print('result')
print needs parentheses.
Python
UPDATE users SET status='info' WHERE role=23
UPDATE users SET status='info' WHERE role=23;
Add semicolon.
SQL
x := 74
x := 74
Correct.
Go
var x = 20;
var x = 20;
Correct.
Dart
void main() {{ print('data') }}
void main() {{ print('data'); }}
Add semicolon.
Dart
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
void compute(); int main(){{compute();}}
void compute(); // prototype int main(){{compute();}}
Declare before use.
C++
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
[x*x for x in list if x > 28]
[x*x for x in list if x > 28]
Correct list comprehension.
Python
#header {{ color: blue; }}
#header {{ color: blue; }}
Correct.
CSS
String data = 'message';
String data = "message";
Double quotes.
Java
echo 'output'
echo 'output';
Add semicolon.
PHP
else print('message')
else: print('message')
Colon after else.
Python
yield y
yield y
Correct yield.
Python
if (c = 10) {}
if (c == 10) {}
Use ==.
Dart
local temp = 54
local temp = 54
Correct.
Lua
JOIN orders ON products.id = orders.email
JOIN orders ON products.id = orders.email
Correct.
SQL
if a = 42 then print('message') end
if a == 42 then print('message') end
Use ==.
Lua
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
// comment
/* comment */
Use /* */.
CSS
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let s1 = String::from("message"); let text2 = s1; println!("{{}}", s1);
let s1 = String::from("message"); let text2 = s1.clone(); println!("{{}}", s1);
Clone to avoid move.
Rust
let bar = 73; let bar = 89;
let bar = 73; bar = 89;
Duplicate declaration.
JavaScript
let data = 15;
let data = 15;
Correct.
JavaScript
let vec=vec![89,34,70]; let primary=&vec[0]; vec.push(65);
let mut vec=vec![89,34,70]; let primary=vec[0]; vec.push(65);
Copy instead of reference.
Rust
{{'name':92, 'title' 24}}
{{'name':92, 'title':24}}
Colon missing.
Python
const c = 71; c = 95;
let c = 71; c = 95;
Cannot reassign const.
JavaScript
val b = 59; b = 70
var b = 59; b = 70
Use var for reassignment.
Scala
<note><desc>test</desc><desc>35</desc></note
<note><desc>test</desc><desc>35</desc></note>
Add closing >.
XML
my @arr = (25,85,17);
my @arr = (25,85,17);
Correct.
Perl
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
class User def method end end
class User def method end end
Correct.
Ruby
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
val c = 'data'
val c = "data"
Double quotes.
Kotlin
<br></br>
<br>
Self-closing.
HTML
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
SELECT * FROM items WHRE status=24;
SELECT * FROM items WHERE status=24;
Fix WHERE.
SQL
if (a = 28)
if (a == 28)
Use ==.
C++
if (a = 35) {{}}
if (a == 35) {{}}
Use ==.
Kotlin
val result: Int = 'message'
val result: String = 'message'
Fix type.
Kotlin
List(68,66,58)
List(68,66,58)
Correct.
Scala
int[] arr = new int[32]; arr[32] = 5;
int[] arr = new int[32]; if (32 < arr.length) arr[32] = 5;
Check bounds.
Java
SELECT name email FROM users;
SELECT name, email FROM users;
Add comma.
SQL
function handle(val) print(val) end
function handle(val) print(val) end
Correct.
Lua
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if c = 1
if c == 1
Use ==.
MATLAB
const num;
const num = 27;
Initialize const.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if data = 32
if data == 32
Use ==.
Go
let mut val=72; let ref1=&mut val; let ref2=&mut val;
let mut val=72; {{ let ref1=&mut val; }} let ref2=&mut val;
Only one mutable borrow.
Rust
68data = 10
data68 = 10
Variable cannot start with digit.
Python
'result' + 58
'result' + str(58)
Can't add int to string.
Python
if (a = 36)
if (a == 36)
Use ==.
R
function render() {{ echo 'info'; }}
function render() {{ echo 'info'; }}
Correct.
PHP
items.forEach(function(a) {{ console.log(a); }})
items.forEach((a) => {{ console.log(a); }})
Arrow functions are cleaner.
JavaScript
p {{ color: red }}
p {{ color: red; }}
Add semicolon.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(67);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(67, () => console.log('listening'));
Add callback.
Node.js
{ "name": "output" }
{ "name": "output" }
Correct.
JSON
{{"status":"value" "title":96}}
{{"status":"value", "title":96}}
Add comma.
JSON
'message' + 40
'message' + 40.to_s
Convert int.
Ruby