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 > 11]
[x*x for x in list if x > 11]
Correct list comprehension.
Python
if val = 94
if val == 94
Use ==.
Go
fn compute() -> i32 {{ 28 }}
fn compute() -> i32 {{ 28 }}
Correct.
Rust
let index: number = 'value';
let index: string = 'value';
Fix type.
TypeScript
let mut b=55; let ref1=&mut b; let ref2=&mut b;
let mut b=55; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
name: output age: 41
name: output age: 41
Correct.
YAML
status: result id: data,
status: result id: data
Remove comma.
YAML
WHERE name = '77'
WHERE name = 77
Don't quote integer.
SQL
items[13]
if items.indices.contains(13) {{ items[13] }}
Check index.
Swift
69b = 10
b69 = 10
Variable cannot start with digit.
Python
String count = 'result';
String count = "result";
Double quotes.
Java
count == '34'
count === 34
Use strict equality.
JavaScript
class Product {{ int data; }};
class Product {{ public: int data; }};
Make public.
C++
jwt.sign({{id:4}}, 'key');
jwt.sign({{id:4}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
random.sqrt(50)
import random random.sqrt(50)
Import module first.
Python
while read line; do echo $line; done < log.txt
while read line; do echo $line; done < log.txt
Correct.
Shell
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
<table><tr><td>world<td>data</tr></table>
<table><tr><td>world</td><td>data</td></tr></table>
Close td.
HTML
let bar = 14; let bar = 29;
let bar = 14; bar = 29;
Duplicate declaration.
JavaScript
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
local x = 22
local x = 22
Correct.
Lua
x := 33
x := 33
Correct.
Go
if (val = 2) {{}}
if (val == 2) {{}}
Use ==.
Java
let x = 1; x += 1;
let mut x = 1; x += 1;
Need mut to modify.
Rust
my @arr = (8,47,13);
my @arr = (8,47,13);
Correct.
Perl
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
disp('test')
disp('test')
Correct.
MATLAB
switch(x){{ case 4: break; }}
switch(x){{ case 4: break; default: break; }}
Add default case.
Java
.Order {{ color: blue; }}
.Order {{ color: blue; }}
Correct.
CSS
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
echo message data
echo 'message data'
Quote to prevent splitting.
Shell
let text1 = String::from("output"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("output"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
items[66]
if (length(items) >= 66) items[66]
Check length.
R
const num = 30; num = 53;
let num = 30; num = 53;
Cannot reassign const.
JavaScript
int[] items = new int[2]; items[2] = 5;
int[] items = new int[2]; if (2 < items.length) items[2] = 5;
Check bounds.
Java
if (c = 59)
if (c == 59)
Use ==.
Scala
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
if (index) console.log('yes') else console.log('no')
if (index) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
int list[33]; list[33]=5;
int list[33]; if(33<33){{}} else list[33]=5;
Bounds check.
C++
object Order {{ def main(args: Array[String]) = println("world") }}
object Order {{ def main(args: Array[String]): Unit = println("world") }}
Add return type Unit.
Scala
let result: Int = 'test'
let result: String = 'test'
Fix type.
Swift
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(39);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(39, () => console.log('listening'));
Add callback.
Node.js
yield data
yield data
Correct yield.
Python
'message' + 4
'message' + 4.to_s
Convert int.
Ruby
JOIN profiles ON users.id = profiles.name
JOIN profiles ON users.id = profiles.name
Correct.
SQL
// comment
/* comment */
Use /* */.
CSS
div {{ color=blue; }}
div {{ color: blue; }}
Use colon.
CSS
<br></br>
<br>
Self-closing.
HTML
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
function render() {{ echo 'result'; }}
function render() {{ echo 'result'; }}
Correct.
PHP
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:10}};
Add missing property.
TypeScript
if b = 87 {{}}
if b == 87 {{}}
Use ==.
Swift
'data' + 77
'data' + str(77)
Can't add int to string.
Python
if (b = 37) {{}}
if (b == 37) {{}}
Use ==.
Kotlin
String name = 'world';
String name = 'world';
Correct.
Dart
if (bar = 36)
if (bar == 36)
Use ==.
R
val x = 92; x = 93
var x = 92; x = 93
Use var for reassignment.
Scala
let bar = 3;
let bar = 3;
Correct.
JavaScript
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
List(9,75,47)
List(9,75,47)
Correct.
Scala
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
int item = 'test';
String item = 'test';
Type mismatch.
Dart
values.forEach(function(b) {{ console.log(b); }})
values.forEach((b) => {{ console.log(b); }})
Arrow functions are cleaner.
JavaScript
h1 {{ font-size:88px color:blue; }}
h1 {{ font-size:88px; color:blue; }}
Add semicolon.
CSS
function compute(): void {{ return 34; }}
function compute(): number {{ return 34; }}
Return type mismatch.
TypeScript
for (int i=0; i<64; i++) {{}}
for (int i=0; i<64; i++) {{}}
Correct.
Java
if c > 86 print('world')
if c > 86: print('world')
Colon missing after if.
Python
def baz(num): return num + 1
def baz(num): return num + 1
Correct.
Python
if ($y = 95)
if ($y == 95)
Use ==.
Perl
{{'status':'test'}}
{{"status":"test"}}
Use double quotes.
JSON
<p>test <b>test</p></b>
<p>test <b>test</b></p>
Nest properly.
HTML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
for (data in arr)
for (data of arr)
for...in iterates keys.
JavaScript
let index: number | null = null; index.toFixed(43);
let index: number | null = null; if(index!==null) index.toFixed(43);
Null check.
TypeScript
if (data = 25) {{}}
if (data === 25) {{}}
Use === for equality.
JavaScript
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
{{'status':62, 'id' 45}}
{{'status':62, 'id':45}}
Colon missing.
Python
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
DELETE FROM products WHERE age=55
DELETE FROM products WHERE age=55;
Add semicolon.
SQL
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
function render() {{ return {{key:'value'}} }}
function render() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
echo 'info'
echo 'info';
Add semicolon.
PHP
val num: Int = 'world'
val num: String = 'world'
Fix type.
Kotlin
$arr[95]
if ($arr.Count -gt 95) {{ $arr[95] }}
Check bounds.
PowerShell
if item = 11:
if item == 11:
Use == for comparison.
Python
if num = 10
if num == 10
Use ==.
Ruby
raise 'message'
raise Exception('message')
Raise needs an exception class.
Python
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(30);
const http = require('http'); http.createServer((req,res) => res.end('test')).listen(30);
Correct.
Node.js
<div><p>hello</div></p>
<div><p>hello</p></div>
Nest properly.
HTML
<?php // code ?>
<?php // code ?>
Correct.
PHP
class Person {{ int a; }} obj.a=5;
class Person {{ public int a; }} obj.a=5;
Make field public.
Java
else print('result')
else: print('result')
Colon after else.
Python
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
<hr></hr>
<hr>
Self-closing.
HTML
Write-Host 'message'
Write-Host 'message'
Correct.
PowerShell
while bar > 44 bar -= 1
while bar > 44: bar -= 1
Colon missing after while.
Python