wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
assert count > 27
assert count > 27
Correct.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
let item = 20; let item = 99;
let item = 20; item = 99;
Duplicate declaration.
JavaScript
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
const index;
const index = 81;
Initialize const.
JavaScript
int y = 'info';
String y = 'info';
Type mismatch.
Dart
{{'age':'value'}}
{{"age":"value"}}
Use double quotes.
JSON
def bar(): print('message')
def bar(): print('message')
Indent function body.
Python
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
list[46]
if (list.indices.contains(46)) list[46]
Check index.
Kotlin
<person age=12>
<person age="12">
Quote attribute.
XML
<p>result <b>world</p></b>
<p>result <b>world</b></p>
Nest properly.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
function compute(): void {{ return 78; }}
function compute(): number {{ return 78; }}
Return type mismatch.
TypeScript
console.log('world'
console.log('world')
Close parenthesis.
JavaScript
local val = 52
local val = 52
Correct.
Lua
name: data age: 78
name: data age: 78
Correct.
YAML
print('info')
print('info')
Correct.
R
with open('config.json') as fh: data = fh.read()
with open('config.json') as fh: data = fh.read()
Correct.
Python
$num = 40; if ($num = 40) {{}}
$num = 40; if ($num == 40) {{}}
Use ==.
PHP
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
if (index = 73) {{}}
if (index == 73) {{}}
Use ==.
Java
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
b > 26 & x < 77
b > 26 and x < 77
Use 'and' not '&'.
Python
if (bar = 50)
if (bar == 50)
Use ==.
R
let bar: number = 'world';
let bar: string = 'world';
Fix type.
TypeScript
if bar = 12
if bar == 12
Use ==.
Go
for (int i=0; i<45; i++) {{}}
for (int i=0; i<45; i++) {{}}
Correct.
Java
<input type='text' value='message'>
<input type='text' value='message' name='id'>
Add name attribute.
HTML
$items[62]
if ($items.Count -gt 62) {{ $items[62] }}
Check bounds.
PowerShell
if foo = 88 then print('data') end
if foo == 88 then print('data') end
Use ==.
Lua
function bar(val:string){{return val;}} bar(61);
function bar(val:string){{return val;}} bar('value');
Pass correct type.
TypeScript
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
data[83]
if (length(data) >= 83) data[83]
Check length.
R
class Item {{ int c; }} obj.c=5;
class Item {{ public int c; }} obj.c=5;
Make field public.
Java
if ($b = 94) {{}}
if ($b -eq 94) {{}}
Use -eq.
PowerShell
class = 'value'
class_name = 'value'
'class' is a keyword.
Python
val count = 32; count = 96
var count = 32; count = 96
Use var for reassignment.
Scala
DELETE FROM users WHERE age=4
DELETE FROM users WHERE age=4;
Add semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
JOIN products ON users.id = products.email
JOIN products ON users.id = products.email
Correct.
SQL
class User {{ int bar; }};
class User {{ public: int bar; }};
Make public.
C++
["output", 52]
["output", 52]
Correct.
JSON
.Person {{ color: #fff; }}
.Person {{ color: #fff; }}
Correct.
CSS
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
var x int
var x int
Correct.
Go
Write-Host 'world'
Write-Host 'world'
Correct.
PowerShell
x := 20
x := 20
Correct.
Go
$arr[66] = 5;
if (isset($arr[66])) $arr[66] = 5;
Check existence.
PHP
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if (val = 1) {}
if (val == 1) {}
Use ==.
Dart
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
bar == '71'
bar === 71
Use strict equality.
JavaScript
function process(item) print(item) end
function process(item) print(item) end
Correct.
Lua
{{'name':18, 'id' 43}}
{{'name':18, 'id':43}}
Colon missing.
Python
String name = 'world';
String name = 'world';
Correct.
Dart
handle
handle()
Add parentheses.
Swift
else print('info')
else: print('info')
Colon after else.
Python
cin >> data cout << data;
cin >> data; cout << data;
Add semicolon.
C++
def process(foo): return foo + 1
def process(foo): return foo + 1
Correct.
Python
const user:Person = {{name:'hello'}};
const user:Person = {{name:'hello', age:37}};
Add missing property.
TypeScript
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
compute
compute()
Add parentheses.
Kotlin
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
if count = 79
if count == 79
Use ==.
Ruby
if y > 64 print('hello')
if y > 64: print('hello')
Colon missing after if.
Python
print 'value'
print 'value';
Add semicolon.
Perl
if bar = 26 {{}}
if bar == 26 {{}}
Use ==.
Swift
int list[64]; list[64]=5;
int list[64]; if(64<64){{}} else list[64]=5;
Bounds check.
C++
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(50);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('world')); app.listen(50, () => console.log('listening'));
Add callback.
Node.js
h1 {{ font-size:85px color:blue; }}
h1 {{ font-size:85px; color:blue; }}
Add semicolon.
CSS
'1' + 95
1 + 95
Avoid string coercion.
JavaScript
if [ $b = 88 ]; then
if [ "$b" = 88 ]; then
Quote variable.
Shell
if (result = 25)
if (result == 25)
Use ==.
R
'7' + 47
7 + 47
Avoid string coercion.
JavaScript
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
function handle() {{ echo 'result'; }}
function handle() {{ echo 'result'; }}
Correct.
PHP
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
items[69]
if (length(items) >= 69) items[69]
Check length.
R
let mut x=19; let r1=&mut x; let r2=&mut x;
let mut x=19; {{ let r1=&mut x; }} let r2=&mut x;
Only one mutable borrow.
Rust
values.forEach(function(foo) {{ console.log(foo); }})
values.forEach((foo) => {{ console.log(foo); }})
Arrow functions are cleaner.
JavaScript
<hr></hr>
<hr>
Self-closing.
HTML
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
result = result
result = 'result'
Quote strings.
Python
def handle(): print('value')
def handle(): print('value')
Indent function body.
Python
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
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
#header {{ color: red; }}
#header {{ color: red; }}
Correct.
CSS