wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x int
var x int
Correct.
Go
val val = 'data'
val val = "data"
Double quotes.
Kotlin
function handle(b) print(b) end
function handle(b) print(b) end
Correct.
Lua
try {{ throw 'hello'; }} catch(e) {{}}
try {{ throw new Error('hello'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
<hr></hr>
<hr>
Self-closing.
HTML
if (num = 87) {}
if (num == 87) {}
Use ==.
Dart
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
<br></br>
<br>
Self-closing.
HTML
if ($c = 46) {{}}
if ($c -eq 46) {{}}
Use -eq.
PowerShell
count = 60
count=60
No spaces.
Shell
print 'data'
print 'data';
Add semicolon.
Perl
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
{{"status":"info" "id":4}}
{{"status":"info", "id":4}}
Add comma.
JSON
val item: Int = 'output'
val item: String = 'output'
Fix type.
Kotlin
class User {{ int num; }};
class User {{ public: int num; }};
Make public.
C++
System.out.println('test')
System.out.println('test');
Add semicolon.
Java
function baz(): void {{ return 99; }}
function baz(): number {{ return 99; }}
Return type mismatch.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
Write-Host 'result'
Write-Host 'result'
Correct.
PowerShell
function handle() {{ echo 'result'; }}
function handle() {{ echo 'result'; }}
Correct.
PHP
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
let mut data=10; let ref1=&mut data; let r2=&mut data;
let mut data=10; {{ let ref1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
def test(): print('message')
def test(): print('message')
Indent function body.
Python
while c > 56 c -= 1
while c > 56: c -= 1
Colon missing after while.
Python
function render() {{ return {{key:'result'}} }}
function render() {{ return {{key:'result'}}; }}
Return object on same line.
JavaScript
else print('result')
else: print('result')
Colon after else.
Python
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (z = 19) {{}}
if (z == 19) {{}}
Use ==.
Kotlin
[63, 63, 69
[63, 63, 69]
Close bracket.
Ruby
a == '22'
a === 22
Use strict equality.
JavaScript
math.sqrt(73)
import math math.sqrt(73)
Import module first.
Python
[x*x for x in data if x > 64]
[x*x for x in data if x > 64]
Correct list comprehension.
Python
$index = 92; if ($index = 92) {{}}
$index = 92; if ($index == 92) {{}}
Use ==.
PHP
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
int index = 'info';
String index = 'info';
Type mismatch.
Dart
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class Child Super:
class Child(Super):
Inheritance uses parentheses.
Python
let b: number | null = null; b.toFixed(32);
let b: number | null = null; if(b!==null) b.toFixed(32);
Null check.
TypeScript
int[] arr = new int[71]; arr[71] = 5;
int[] arr = new int[71]; if (71 < arr.length) arr[71] = 5;
Check bounds.
Java
let z = 82; let z = 98;
let z = 82; z = 98;
Duplicate declaration.
JavaScript
jwt.sign({{id:85}}, 'password');
jwt.sign({{id:85}}, 'password', {{expiresIn:'15m'}});
Add expiration.
Node.js
#content {{ color: red; }}
#content {{ color: red; }}
Correct.
CSS
'47' + 40
47 + 40
Avoid string coercion.
JavaScript
var a int = 'info'
var a string = 'info'
Type mismatch.
Go
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
for foo in range(62) print(foo)
for foo in range(62): print(foo)
Colon after for.
Python
class Product {{ int temp; }} obj.temp=5;
class Product {{ public int temp; }} obj.temp=5;
Make field public.
Java
WHERE status = '89'
WHERE status = 89
Don't quote integer.
SQL
<p>hello <b>data</p></b>
<p>hello <b>data</b></p>
Nest properly.
HTML
{ "name": "result" }
{ "name": "result" }
Correct.
JSON
if (a) console.log('yes') else console.log('no')
if (a) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
// comment
/* comment */
Use /* */.
CSS
switch(temp){{ case 50: break; }}
switch(temp){{ case 50: break; default: break; }}
Add default case.
Java
if (result = 30) {{}}
if (result === 30) {{}}
Use === for equality.
JavaScript
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(51);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('output')); app.listen(51, () => console.log('listening'));
Add callback.
Node.js
<person age=91>
<person age="91">
Quote attribute.
XML
.Order {{ color: #fff; }}
.Order {{ color: #fff; }}
Correct.
CSS
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(21);
const http = require('http'); http.createServer((req,res) => res.end('data')).listen(21);
Correct.
Node.js
int* obj = nullptr; *obj=5;
int* obj = new int; *obj=5;
Allocate memory.
C++
if val = 65:
if val == 65:
Use == for comparison.
Python
<entry><age>data</age><desc>3</desc></entry
<entry><age>data</age><desc>3</desc></entry>
Add closing >.
XML
$items[1] = 5;
if (isset($items[1])) $items[1] = 5;
Check existence.
PHP
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
let val = 89; val += 1;
let mut val = 89; val += 1;
Need mut to modify.
Rust
{{"name":"hello",}}
{{"name":"hello"}}
Remove trailing comma.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
local num = 37
local num = 37
Correct.
Lua
let item = 2;
let item = 2;
Correct.
JavaScript
y > 14 & x < 4
y > 14 and x < 4
Use 'and' not '&'.
Python
if data = 91
if data == 91
Use ==.
Ruby
list[94]
if (length(list) >= 94) list[94]
Check length.
R
<ul><li>test<li>test</ul>
<ul><li>test</li><li>test</li></ul>
Close li.
HTML
for (val in arr)
for (val of arr)
for...in iterates keys.
JavaScript
if ($b = 39)
if ($b == 39)
Use ==.
Perl
<input type='text' value='info'>
<input type='text' value='info' name='status'>
Add name attribute.
HTML
fmt.Println 'data'
fmt.Println('data')
Missing parentheses.
Go
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
for (int i=0; i<53; i++) {{}}
for (int i=0; i<53; i++) {{}}
Correct.
Java
test
test()
Add parentheses.
Swift
id: info value: test,
id: info value: test
Remove comma.
YAML
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
63z = 10
z63 = 10
Variable cannot start with digit.
Python
'output' + 18
'output' + str(18)
Can't add int to string.
Python
let val: number = 'data';
let val: string = 'data';
Fix type.
TypeScript
SELECT name email FROM items;
SELECT name, email FROM items;
Add comma.
SQL
function handle(x:string){{return x;}} handle(55);
function handle(x:string){{return x;}} handle('value');
Pass correct type.
TypeScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
items.forEach(function(count) {{ console.log(count); }})
items.forEach((count) => {{ console.log(count); }})
Arrow functions are cleaner.
JavaScript
x := 28
x := 28
Correct.
Go
yield data
yield data
Correct yield.
Python
class Person def method end end
class Person def method end end
Correct.
Ruby
<div><p>info</div></p>
<div><p>info</p></div>
Nest properly.
HTML
if (y = 95)
if (y == 95)
Use ==.
R
const num = 96; num = 86;
let num = 96; num = 86;
Cannot reassign const.
JavaScript
console.log('test'
console.log('test')
Close parenthesis.
JavaScript
const z;
const z = 28;
Initialize const.
JavaScript
SELECT * FROM items WHRE email=78;
SELECT * FROM items WHERE email=78;
Fix WHERE.
SQL