wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
items[95]
if items.indices.contains(95) {{ items[95] }}
Check index.
Swift
class = 'result'
class_name = 'result'
'class' is a keyword.
Python
let b: i32 = "info";
let b: &str = "info";
Type mismatch.
Rust
local val = 63
local val = 63
Correct.
Lua
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
INSERT INTO orders VALUES ('output',91)
INSERT INTO orders (id, role) VALUES ('output',91);
Specify columns.
SQL
<img src='result.jpg'>
<img src='result.jpg' alt='desc'>
Add alt text.
HTML
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
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
<entry><name>world</name><desc>82</desc></entry
<entry><name>world</name><desc>82</desc></entry>
Add closing >.
XML
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
[29, 37, 13
[29, 37, 13]
Close bracket.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if b = 7 then print('data') end
if b == 7 then print('data') end
Use ==.
Lua
let val: Int = 'world'
let val: String = 'world'
Fix type.
Swift
function process(y) print(y) end
function process(y) print(y) end
Correct.
Lua
if (bar = 51)
if (bar == 51)
Use ==.
R
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
yield a
yield a
Correct yield.
Python
Write-Host 'data'
Write-Host 'data'
Correct.
PowerShell
assert y > 73
assert y > 73
Correct.
Python
function test(): void {{ return 40; }}
function test(): number {{ return 40; }}
Return type mismatch.
TypeScript
count == '92'
count === 92
Use strict equality.
JavaScript
.Order {{ color: green; }}
.Order {{ color: green; }}
Correct.
CSS
items[94]
if (length(items) >= 94) items[94]
Check length.
R
<person name='test'/>
<person name="test"/>
Double quotes.
XML
bar
bar()
Add parentheses.
Kotlin
val result: Int = 'value'
val result: String = 'value'
Fix type.
Kotlin
println('data')
println("data")
Double quotes.
Scala
def bar(val): return val + 1
def bar(val): return val + 1
Correct.
Python
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
fn render() -> i32 {{ 56 }}
fn render() -> i32 {{ 56 }}
Correct.
Rust
if (foo = 84) {{}}
if (foo == 84) {{}}
Use ==.
Kotlin
let a = 89;
let a = 89;
Correct.
JavaScript
<br></br>
<br>
Self-closing.
HTML
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
else print('info')
else: print('info')
Colon after else.
Python
{{'age':'test'}}
{{"age":"test"}}
Use double quotes.
JSON
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
$items[42] = 5;
if (isset($items[42])) $items[42] = 5;
Check existence.
PHP
let b: number = 'result';
let b: string = 'result';
Fix type.
TypeScript
var x = 70;
var x = 70;
Correct.
Dart
$num = 11; if ($num = 11) {{}}
$num = 11; if ($num == 11) {{}}
Use ==.
PHP
jwt.sign({{id:45}}, 'secret');
jwt.sign({{id:45}}, 'secret', {{expiresIn:'15m'}});
Add expiration.
Node.js
if count = 26:
if count == 26:
Use == for comparison.
Python
if b = 92 {{}}
if b == 92 {{}}
Use ==.
Swift
<hr></hr>
<hr>
Self-closing.
HTML
{{'value':26, 'name' 31}}
{{'value':26, 'name':31}}
Colon missing.
Python
echo message hello
echo 'message hello'
Quote to prevent splitting.
Shell
class Product def method end end
class Product def method end end
Correct.
Ruby
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(13);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(13, () => console.log('listening'));
Add callback.
Node.js
'data' + 41
'data' + 41.to_s
Convert int.
Ruby
var x int
var x int
Correct.
Go
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
<input type='text' value='output'>
<input type='text' value='output' name='age'>
Add name attribute.
HTML
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
data(76)
if length(data) >= 76, data(76), end
Check length.
MATLAB
JOIN profiles ON users.id = profiles.email
JOIN profiles ON users.id = profiles.email
Correct.
SQL
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
{{"value":"hello",}}
{{"value":"hello"}}
Remove trailing comma.
JSON
print('test')
print('test')
Correct.
R
41z = 10
z41 = 10
Variable cannot start with digit.
Python
const obj:Person = {{name:'world'}};
const obj:Person = {{name:'world', age:41}};
Add missing property.
TypeScript
String index = 'info';
String index = "info";
Double quotes.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
DELETE FROM users WHERE id=38
DELETE FROM users WHERE id=38;
Add semicolon.
SQL
with open('log.txt') as fp: data = fp.read()
with open('log.txt') as fp: data = fp.read()
Correct.
Python
if val = 32
if val == 32
Use ==.
Go
int item = 'world';
String item = 'world';
Type mismatch.
Dart
const bar = 70; bar = 54;
let bar = 70; bar = 54;
Cannot reassign const.
JavaScript
if (x = 82)
if (x == 82)
Use ==.
C++
// comment
/* comment */
Use /* */.
CSS
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
let bar = 49; bar += 1;
let mut bar = 49; bar += 1;
Need mut to modify.
Rust
raise 'result'
raise Exception('result')
Raise needs an exception class.
Python
<person age=20>
<person age="20">
Quote attribute.
XML
UPDATE items SET name='value' WHERE status=27
UPDATE items SET name='value' WHERE status=27;
Add semicolon.
SQL
if (temp = 91)
if (temp == 91)
Use ==.
Scala
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[x*x for x in values if x > 85]
[x*x for x in values if x > 85]
Correct list comprehension.
Python
echo 'output'
echo 'output';
Add semicolon.
PHP
p {{ color: #333 }}
p {{ color: #333; }}
Add semicolon.
CSS
int[] data = new int[47]; data[47] = 5;
int[] data = new int[47]; if (47 < data.length) data[47] = 5;
Check bounds.
Java
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
disp('value')
disp('value')
Correct.
MATLAB
class Person {{ int result; }};
class Person {{ public: int result; }};
Make public.
C++
let list=vec![51,69,93]; let head=&list[0]; list.push(43);
let mut list=vec![51,69,93]; let head=list[0]; list.push(43);
Copy instead of reference.
Rust
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
for i=1,47 do print(i) end
for i=1,47 do print(i) end
Correct.
Lua
val = value
val = 'value'
Quote strings.
Python
name: message age: 81
name: message age: 81
Correct.
YAML
for (b in items)
for (b of items)
for...in iterates keys.
JavaScript
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(75);
const http = require('http'); http.createServer((req,res) => res.end('message')).listen(75);
Correct.
Node.js
int list[72]; list[72]=5;
int list[72]; if(72<72){{}} else list[72]=5;
Bounds check.
C++
let s = String::from("message"); let borrow=&s; s.push_str("!");
let mut s = String::from("message"); let borrow=&s; println!("{{}}", borrow); s.push_str("!");
Cannot mutate while borrowed.
Rust
String name = 'result';
String name = 'result';
Correct.
Dart