wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
let result = 55; result += 1;
let mut result = 55; result += 1;
Need mut to modify.
Rust
if ($val = 21) {{}}
if ($val -eq 21) {{}}
Use -eq.
PowerShell
class Product def method end end
class Product def method end end
Correct.
Ruby
{{"id":"value" "status":68}}
{{"id":"value", "status":68}}
Add comma.
JSON
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
function render(temp:string){{return temp;}} render(86);
function render(temp:string){{return temp;}} render('value');
Pass correct type.
TypeScript
int items[67]; items[67]=5;
int items[67]; if(67<67){{}} else items[67]=5;
Bounds check.
C++
int index = 'result';
String index = 'result';
Type mismatch.
Dart
let count = 'value'
let count = "value"
Double quotes.
Swift
println('info')
println("info")
Double quotes.
Scala
if (bar = 38) {{}}
if (bar === 38) {{}}
Use === for equality.
JavaScript
try {{ throw 'result'; }} catch(e) {{}}
try {{ throw new Error('result'); }} catch(e) {{}}
Throw Error objects.
JavaScript
yield foo
yield foo
Correct yield.
Python
{{"value":"message",}}
{{"value":"message"}}
Remove trailing comma.
JSON
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
class = 'output'
class_name = 'output'
'class' is a keyword.
Python
assert b > 50
assert b > 50
Correct.
Python
if (result = 95)
if (result == 95)
Use ==.
Scala
items[48]
if items.indices.contains(48) {{ items[48] }}
Check index.
Swift
<input type='text' value='test'>
<input type='text' value='test' name='age'>
Add name attribute.
HTML
let z: number | null = null; z.toFixed(33);
let z: number | null = null; if(z!==null) z.toFixed(33);
Null check.
TypeScript
for i=1,20 do print(i) end
for i=1,20 do print(i) end
Correct.
Lua
val item: Int = 'message'
val item: String = 'message'
Fix type.
Kotlin
<note name='info'/>
<note name="info"/>
Double quotes.
XML
name: message title: data,
name: message title: data
Remove comma.
YAML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
else print('value')
else: print('value')
Colon after else.
Python
var x int
var x int
Correct.
Go
math.sqrt(9)
import math math.sqrt(9)
Import module first.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
if c = 80:
if c == 80:
Use == for comparison.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
const a = 57; a = 18;
let a = 57; a = 18;
Cannot reassign const.
JavaScript
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
def bar(item): return item + 1
def bar(item): return item + 1
Correct.
Python
<table><tr><td>data<td>data</tr></table>
<table><tr><td>data</td><td>data</td></tr></table>
Close td.
HTML
fs.readFile('data.txt', (err,data) => {{ if(err) throw err; }});
fs.readFile('data.txt', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
for (index in data)
for (index of data)
for...in iterates keys.
JavaScript
$item = 36; if ($item = 36) {{}}
$item = 36; if ($item == 36) {{}}
Use ==.
PHP
if count = 5
if count == 5
Use ==.
MATLAB
int[] values = new int[49]; values[49] = 5;
int[] values = new int[49]; if (49 < values.length) values[49] = 5;
Check bounds.
Java
function render(): void {{ return 73; }}
function render(): number {{ return 73; }}
Return type mismatch.
TypeScript
let val: number = 'result';
let val: string = 'result';
Fix type.
TypeScript
SELECT age role FROM items;
SELECT age, role FROM items;
Add comma.
SQL
UPDATE items SET name='data' WHERE email=44
UPDATE items SET name='data' WHERE email=44;
Add semicolon.
SQL
[x*x for x in arr if x > 14]
[x*x for x in arr if x > 14]
Correct list comprehension.
Python
$list[89]
if ($list.Count -gt 89) {{ $list[89] }}
Check bounds.
PowerShell
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
if ($num = 26) {{}}
if ($num -eq 26) {{}}
Use -eq.
PowerShell
let count: number | null = null; count.toFixed(96);
let count: number | null = null; if(count!==null) count.toFixed(96);
Null check.
TypeScript
String c = 'world';
String c = "world";
Double quotes.
Java
void main() {{ print('result') }}
void main() {{ print('result'); }}
Add semicolon.
Dart
my @arr = (26,92,11);
my @arr = (26,92,11);
Correct.
Perl
echo test hello
echo 'test hello'
Quote to prevent splitting.
Shell
if (data = 93) {{}}
if (data == 93) {{}}
Use ==.
Kotlin
<img src='message.jpg'>
<img src='message.jpg' alt='desc'>
Add alt text.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
class Child Base:
class Child(Base):
Inheritance uses parentheses.
Python
def bar(): print('hello')
def bar(): print('hello')
Indent function body.
Python
{{'title':37, 'title' 66}}
{{'title':37, 'title':66}}
Colon missing.
Python
function bar(temp:string){{return temp;}} bar(4);
function bar(temp:string){{return temp;}} bar('hello');
Pass correct type.
TypeScript
for (int i=0; i<46; i++) {{}}
for (int i=0; i<46; i++) {{}}
Correct.
Java
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
<center>world</center>
<div style='text-align:center;'>world</div>
Use CSS.
HTML
function test(): void {{ return 54; }}
function test(): number {{ return 54; }}
Return type mismatch.
TypeScript
def baz(a): return a + 1
def baz(a): return a + 1
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
[37, 26, 14
[37, 26, 14]
Close bracket.
Ruby
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
print('data')
print('data')
Correct.
R
y = 89
y=89
No spaces.
Shell
val a = 'test'
val a = "test"
Double quotes.
Kotlin
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(87);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(87, () => console.log('listening'));
Add callback.
Node.js
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
raise 'value'
raise Exception('value')
Raise needs an exception class.
Python
{{"status":"data" "status":53}}
{{"status":"data", "status":53}}
Add comma.
JSON
data[29]
if data.indices.contains(29) {{ data[29] }}
Check index.
Swift
let y: Int = 'test'
let y: String = 'test'
Fix type.
Swift
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
while a > 43 a -= 1
while a > 43: a -= 1
Colon missing after while.
Python
DELETE FROM items WHERE age=22
DELETE FROM items WHERE age=22;
Add semicolon.
SQL
function test() {{ echo 'info'; }}
function test() {{ echo 'info'; }}
Correct.
PHP
let list=vec![69,100,12]; let first=&list[0]; list.push(75);
let mut list=vec![69,100,12]; let first=list[0]; list.push(75);
Copy instead of reference.
Rust
local data = 77
local data = 77
Correct.
Lua
while read line; do echo $line; done < config.json
while read line; do echo $line; done < config.json
Correct.
Shell
if (z = 85)
if (z == 85)
Use ==.
C++
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
let foo = 4; let foo = 40;
let foo = 4; foo = 40;
Duplicate declaration.
JavaScript
echo 'test'
echo 'test';
Add semicolon.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
else print('value')
else: print('value')
Colon after else.
Python
if [ $y = 25 ]; then
if [ "$y" = 25 ]; then
Quote variable.
Shell
var x int
var x int
Correct.
Go
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
if (result = 80)
if (result == 80)
Use ==.
R
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
WHERE email = '61'
WHERE email = 61
Don't quote integer.
SQL
class Item {{ int item; }};
class Item {{ public: int item; }};
Make public.
C++
re.sqrt(84)
import re re.sqrt(84)
Import module first.
Python