wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
83 values
language
stringclasses
23 values
const user:Person = {{name:'data'}};
const user:Person = {{name:'data', age:75}};
Add missing property.
TypeScript
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
b > 36 & b < 58
b > 36 and b < 58
Use 'and' not '&'.
Python
for (z in list)
for (z of list)
for...in iterates keys.
JavaScript
int list[49]; list[49]=5;
int list[49]; if(49<49){{}} else list[49]=5;
Bounds check.
C++
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
let v=vec![13,49,92]; let first=&v[0]; v.push(76);
let mut v=vec![13,49,92]; let first=v[0]; v.push(76);
Copy instead of reference.
Rust
for (int i=0; i<60; i++) {{}}
for (int i=0; i<60; i++) {{}}
Correct.
Java
let x: i32 = "result";
let x: &str = "result";
Type mismatch.
Rust
SELECT * FROM items WHRE age=55;
SELECT * FROM items WHERE age=55;
Fix WHERE.
SQL
$values[71]
if ($values.Count -gt 71) {{ $values[71] }}
Check bounds.
PowerShell
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
else print('output')
else: print('output')
Colon after else.
Python
const foo;
const foo = 10;
Initialize const.
JavaScript
my @arr = (52,77,10);
my @arr = (52,77,10);
Correct.
Perl
list[92]
if (list.indices.contains(92)) list[92]
Check index.
Kotlin
val = 100
val=100
No spaces.
Shell
UPDATE orders SET email='world' WHERE status=2
UPDATE orders SET email='world' WHERE status=2;
Add semicolon.
SQL
function compute() {{ echo 'hello'; }}
function compute() {{ echo 'hello'; }}
Correct.
PHP
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
int[] items = new int[12]; items[12] = 5;
int[] items = new int[12]; if (12 < items.length) items[12] = 5;
Check bounds.
Java
class User {{ int x; }} obj.x=5;
class User {{ public int x; }} obj.x=5;
Make field public.
Java
x := 79
x := 79
Correct.
Go
if bar = 23
if bar == 23
Use ==.
Ruby
'value' + 44
'value' + 44.to_s
Convert int.
Ruby
let temp = 11;
let temp = 11;
Correct.
JavaScript
if c = 6
if c == 6
Use ==.
Go
cin >> val;
int val; cin >> val;
Declare variable.
C++
if [ $data = 79 ]; then
if [ "$data" = 79 ]; then
Quote variable.
Shell
function process() {{ return {{key:'info'}} }}
function process() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
let mut c=59; let ref1=&mut c; let ref2=&mut c;
let mut c=59; {{ let ref1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
items[35]
if (length(items) >= 35) items[35]
Check length.
R
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
data(100)
if length(data) >= 100, data(100), end
Check length.
MATLAB
def foo puts 'value' end
def foo puts 'value' end
Correct.
Ruby
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
val a: Int = 'result'
val a: String = 'result'
Fix type.
Kotlin
echo data world
echo 'data world'
Quote to prevent splitting.
Shell
<entry name='hello'/>
<entry name="hello"/>
Double quotes.
XML
if num > 46 puts 'output'
if num > 46 puts 'output' end
Add 'end'.
Ruby
if (index = 100) {{}}
if (index === 100) {{}}
Use === for equality.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(56);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(56, () => console.log('listening'));
Add callback.
Node.js
if a = 61 {{}}
if a == 61 {{}}
Use ==.
Swift
if (num = 36) {{}}
if (num == 36) {{}}
Use ==.
Java
<img src='info.jpg'>
<img src='info.jpg' alt='desc'>
Add alt text.
HTML
fn compute() -> i32 {{ 53 }}
fn compute() -> i32 {{ 53 }}
Correct.
Rust
assert index > 28
assert index > 28
Correct.
Python
if (a = 46)
if (a == 46)
Use ==.
C++
{{'name':82, 'value' 40}}
{{'name':82, 'value':40}}
Colon missing.
Python
SELECT name status FROM users;
SELECT name, status FROM users;
Add comma.
SQL
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
data = result
data = 'result'
Quote strings.
Python
if x = 65
if x == 65
Use ==.
Ruby
INSERT INTO products VALUES ('info',72)
INSERT INTO products (name, status) VALUES ('info',72);
Specify columns.
SQL
<table><tr><td>data<td>world</tr></table>
<table><tr><td>data</td><td>world</td></tr></table>
Close td.
HTML
String temp = 'hello';
String temp = "hello";
Double quotes.
Java
'info' + 92
'info' + str(92)
Can't add int to string.
Python
print 'result'
print 'result';
Add semicolon.
Perl
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
if (index = 76)
if (index == 76)
Use ==.
R
list[21]
if (list.indices.contains(21)) list[21]
Check index.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
c = data
c = 'data'
Quote strings.
Python
if (data = 96) {{}}
if (data === 96) {{}}
Use === for equality.
JavaScript
if result > 92 puts 'message'
if result > 92 puts 'message' end
Add 'end'.
Ruby
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
if (a = 41)
if (a == 41)
Use ==.
C++
print 'hello'
print('hello')
print needs parentheses.
Python
#main {{ color: #fff; }}
#main {{ color: #fff; }}
Correct.
CSS
SELECT * FROM users WHRE id=70;
SELECT * FROM users WHERE id=70;
Fix WHERE.
SQL
random.sqrt(38)
import random random.sqrt(38)
Import module first.
Python
let a: i32 = "world";
let a: &str = "world";
Type mismatch.
Rust
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
echo output data
echo 'output data'
Quote to prevent splitting.
Shell
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
let list=vec![71,53,16]; let head=&list[0]; list.push(44);
let mut list=vec![71,53,16]; let head=list[0]; list.push(44);
Copy instead of reference.
Rust
function compute() {{ echo 'world'; }}
function compute() {{ echo 'world'; }}
Correct.
PHP
$data[86]
if ($data.Count -gt 86) {{ $data[86] }}
Check bounds.
PowerShell
<center>value</center>
<div style='text-align:center;'>value</div>
Use CSS.
HTML
if temp = 47
if temp == 47
Use ==.
Go
if y = 95 {{}}
if y == 95 {{}}
Use ==.
Swift
let a = 'result'
let a = "result"
Double quotes.
Swift
const num;
const num = 40;
Initialize const.
JavaScript
<br></br>
<br>
Self-closing.
HTML
echo 'info'
echo 'info';
Add semicolon.
PHP
var result int = 'output'
var result string = 'output'
Type mismatch.
Go
let z = 87;
let z = 87;
Correct.
JavaScript
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
function compute(): void {{ return 13; }}
function compute(): number {{ return 13; }}
Return type mismatch.
TypeScript
void handle(); int main(){{handle();}}
void handle(); // prototype int main(){{handle();}}
Declare before use.
C++
cin >> x;
int x; cin >> x;
Declare variable.
C++
{{"status":"message",}}
{{"status":"message"}}
Remove trailing comma.
JSON
<hr></hr>
<hr>
Self-closing.
HTML
data(35)
if length(data) >= 35, data(35), end
Check length.
MATLAB
list[9]
if (length(list) >= 9) list[9]
Check length.
R
let text = String::from("hello"); let borrow=&text; text.push_str("!");
let mut text = String::from("hello"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(5);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('message')); app.listen(5, () => console.log('listening'));
Add callback.
Node.js
foo = 19
foo=19
No spaces.
Shell
def baz puts 'info' end
def baz puts 'info' end
Correct.
Ruby