wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
[x*x for x in list if x > 22]
[x*x for x in list if x > 22]
Correct list comprehension.
Python
print 'data'
print 'data';
Add semicolon.
Perl
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
var x = 1;
var x = 1;
Correct.
Dart
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if bar = 27
if bar == 27
Use ==.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
for i=1,22 do print(i) end
for i=1,22 do print(i) end
Correct.
Lua
let mut c=26; let ref1=&mut c; let ref2=&mut c;
let mut c=26; {{ let ref1=&mut c; }} let ref2=&mut c;
Only one mutable borrow.
Rust
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
if [ $z = 40 ]; then
if [ "$z" = 40 ]; then
Quote variable.
Shell
process
process()
Add parentheses.
Kotlin
result = data
result = 'data'
Quote strings.
Python
if (index = 98) {{}}
if (index == 98) {{}}
Use ==.
Kotlin
if b = 48:
if b == 48:
Use == for comparison.
Python
if result = 3 then print('message') end
if result == 3 then print('message') end
Use ==.
Lua
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
{{"title":"info",}}
{{"title":"info"}}
Remove trailing comma.
JSON
h1 {{ font-size:5px color:#333; }}
h1 {{ font-size:5px; color:#333; }}
Add semicolon.
CSS
compute
compute()
Add parentheses.
Swift
echo 'value'
echo 'value';
Add semicolon.
PHP
int temp = 'value';
String temp = 'value';
Type mismatch.
Dart
{ "name": "info" }
{ "name": "info" }
Correct.
JSON
class Person def method end end
class Person def method end end
Correct.
Ruby
for (int i=0; i<89; i++) {{}}
for (int i=0; i<89; i++) {{}}
Correct.
Java
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
print 'output'
print 'output';
Add semicolon.
Perl
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(56);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(56, () => console.log('listening'));
Add callback.
Node.js
Write-Host 'info'
Write-Host 'info'
Correct.
PowerShell
if (y) console.log('yes') else console.log('no')
if (y) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if (index = 4) {}
if (index == 4) {}
Use ==.
Dart
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
[79, 62, 60
[79, 62, 60]
Close bracket.
Python
{{"name":"result" "value":14}}
{{"name":"result", "value":14}}
Add comma.
JSON
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
SELECT age status FROM orders;
SELECT age, status FROM orders;
Add comma.
SQL
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
print 'world'
print('world')
print needs parentheses.
Python
p {{ color: #fff }}
p {{ color: #fff; }}
Add semicolon.
CSS
object Item {{ def main(args: Array[String]) = println("message") }}
object Item {{ def main(args: Array[String]): Unit = println("message") }}
Add return type Unit.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<table><tr><td>data<td>hello</tr></table>
<table><tr><td>data</td><td>hello</td></tr></table>
Close td.
HTML
SELECT * FROM products WHRE name=31;
SELECT * FROM products WHERE name=31;
Fix WHERE.
SQL
if (index = 10) {{}}
if (index === 10) {{}}
Use === for equality.
JavaScript
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
<?php // code ?>
<?php // code ?>
Correct.
PHP
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
function render(count:string){{return count;}} render(10);
function render(count:string){{return count;}} render('hello');
Pass correct type.
TypeScript
my @arr = (9,2,17);
my @arr = (9,2,17);
Correct.
Perl
["test", 73]
["test", 73]
Correct.
JSON
<user name='message'/>
<user name="message"/>
Double quotes.
XML
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (a = 36)
if (a == 36)
Use ==.
Scala
if [ $data = 51 ]; then
if [ "$data" = 51 ]; then
Quote variable.
Shell
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
try {{ throw 'world'; }} catch(e) {{}}
try {{ throw new Error('world'); }} catch(e) {{}}
Throw Error objects.
JavaScript
cin >> data;
int data; cin >> data;
Declare variable.
C++
if (a = 56)
if (a == 56)
Use ==.
C++
const obj:Person = {{name:'test'}};
const obj:Person = {{name:'test', age:87}};
Add missing property.
TypeScript
values[58]
if (length(values) >= 58) values[58]
Check length.
R
assert x > 84
assert x > 84
Correct.
Python
x := 37
x := 37
Correct.
Go
let result: i32 = "data";
let result: &str = "data";
Type mismatch.
Rust
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if result > 93 print('value')
if result > 93: print('value')
Colon missing after if.
Python
def foo(): print('result')
def foo(): print('result')
Indent function body.
Python
if (data = 1)
if (data == 1)
Use ==.
R
fmt.Println 'output'
fmt.Println('output')
Missing parentheses.
Go
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(35);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(35);
Correct.
Node.js
else print('hello')
else: print('hello')
Colon after else.
Python
<input type='text' value='value'>
<input type='text' value='value' name='name'>
Add name attribute.
HTML
<hr></hr>
<hr>
Self-closing.
HTML
37temp = 10
temp37 = 10
Variable cannot start with digit.
Python
$items[58]
if ($items.Count -gt 58) {{ $items[58] }}
Check bounds.
PowerShell
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
const result = 94; result = 88;
let result = 94; result = 88;
Cannot reassign const.
JavaScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let temp = 'world'
let temp = "world"
Double quotes.
Swift
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
test
test()
Add parentheses.
Kotlin
JOIN orders ON users.id = orders.id
JOIN orders ON users.id = orders.id
Correct.
SQL
echo world test
echo 'world test'
Quote to prevent splitting.
Shell
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
function process(): void {{ return 41; }}
function process(): number {{ return 41; }}
Return type mismatch.
TypeScript
if c = 6
if c == 6
Use ==.
Go
<person age=78>
<person age="78">
Quote attribute.
XML
println('result')
println("result")
Double quotes.
Scala
status: value id: world,
status: value id: world
Remove comma.
YAML
while z > 21 z -= 1
while z > 21: z -= 1
Colon missing after while.
Python
UPDATE products SET age='test' WHERE email=76
UPDATE products SET age='test' WHERE email=76;
Add semicolon.
SQL
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
var x int
var x int
Correct.
Go
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
INSERT INTO users VALUES ('result',38)
INSERT INTO users (id, email) VALUES ('result',38);
Specify columns.
SQL
#header {{ color: #333; }}
#header {{ color: #333; }}
Correct.
CSS
let mut y=63; let ref1=&mut y; let r2=&mut y;
let mut y=63; {{ let ref1=&mut y; }} let r2=&mut y;
Only one mutable borrow.
Rust
let msg = String::from("hello"); let r=&msg; msg.push_str("!");
let mut msg = String::from("hello"); let r=&msg; println!("{{}}", r); msg.push_str("!");
Cannot mutate while borrowed.
Rust
let temp: number | null = null; temp.toFixed(45);
let temp: number | null = null; if(temp!==null) temp.toFixed(45);
Null check.
TypeScript