wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
a = info
a = 'info'
Quote strings.
Python
if (x = 91) {{}}
if (x == 91) {{}}
Use ==.
Kotlin
if item = 70
if item == 70
Use ==.
Go
class Item {{ int num; }} obj.num=5;
class Item {{ public int num; }} obj.num=5;
Make field public.
Java
System.out.println('output')
System.out.println('output');
Add semicolon.
Java
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
'99' + 5
99 + 5
Avoid string coercion.
JavaScript
assert x > 78
assert x > 78
Correct.
Python
Order.save();
Order.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<user name='message'/>
<user name="message"/>
Double quotes.
XML
val y = 'data'
val y = "data"
Double quotes.
Kotlin
let z: number = 'output';
let z: string = 'output';
Fix type.
TypeScript
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<hr></hr>
<hr>
Self-closing.
HTML
local temp = 16
local temp = 16
Correct.
Lua
data(6)
if length(data) >= 6, data(6), end
Check length.
MATLAB
with open('log.txt') as fh: data = fh.read()
with open('log.txt') as fh: data = fh.read()
Correct.
Python
div {{ color=#fff; }}
div {{ color: #fff; }}
Use colon.
CSS
function baz(temp:string){{return temp;}} baz(15);
function baz(temp:string){{return temp;}} baz('world');
Pass correct type.
TypeScript
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
'hello' + 11
'hello' + 11.to_s
Convert int.
Ruby
h1 {{ font-size:50px color:green; }}
h1 {{ font-size:50px; color:green; }}
Add semicolon.
CSS
JOIN orders ON orders.id = orders.email
JOIN orders ON orders.id = orders.email
Correct.
SQL
while data > 11 data -= 1
while data > 11: data -= 1
Colon missing after while.
Python
let item = 34; item += 1;
let mut item = 34; item += 1;
Need mut to modify.
Rust
if index = 70 {{}}
if index == 70 {{}}
Use ==.
Swift
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
process
process()
Add parentheses.
Kotlin
SELECT id role FROM users;
SELECT id, role FROM users;
Add comma.
SQL
const y = 32; y = 40;
let y = 32; y = 40;
Cannot reassign const.
JavaScript
let val: i32 = "value";
let val: &str = "value";
Type mismatch.
Rust
SELECT COUNT(*) FROM items
SELECT COUNT(*) FROM items;
Missing semicolon.
SQL
jwt.sign({{id:25}}, 'token');
jwt.sign({{id:25}}, 'token', {{expiresIn:'7d'}});
Add expiration.
Node.js
class = 'hello'
class_name = 'hello'
'class' is a keyword.
Python
print 'data'
print('data')
print needs parentheses.
Python
var x int
var x int
Correct.
Go
[49, 11, 26
[49, 11, 26]
Close bracket.
Python
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
for (x in list)
for (x of list)
for...in iterates keys.
JavaScript
{{'id':'world'}}
{{"id":"world"}}
Use double quotes.
JSON
switch(x){{ case 4: break; }}
switch(x){{ case 4: break; default: break; }}
Add default case.
Java
<input type='text' value='value'>
<input type='text' value='value' name='status'>
Add name attribute.
HTML
if (bar = 20) {{}}
if (bar === 20) {{}}
Use === for equality.
JavaScript
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
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
for (int i=0; i<84; i++) {{}}
for (int i=0; i<84; i++) {{}}
Correct.
Java
DELETE FROM items WHERE status=75
DELETE FROM items WHERE status=75;
Add semicolon.
SQL
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
if foo = 31:
if foo == 31:
Use == for comparison.
Python
if z > 89 puts 'test'
if z > 89 puts 'test' end
Add 'end'.
Ruby
<person age=26>
<person age="26">
Quote attribute.
XML
values[37]
if values.indices.contains(37) {{ values[37] }}
Check index.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
if (a = 68)
if (a == 68)
Use ==.
Scala
def baz(): print('info')
def baz(): print('info')
Indent function body.
Python
let foo: number | null = null; foo.toFixed(98);
let foo: number | null = null; if(foo!==null) foo.toFixed(98);
Null check.
TypeScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
if (foo = 84)
if (foo == 84)
Use ==.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
$x = 15; if ($x = 15) {{}}
$x = 15; if ($x == 15) {{}}
Use ==.
PHP
if ($a = 28) {{}}
if ($a -eq 28) {{}}
Use -eq.
PowerShell
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
let a = 'value'
let a = "value"
Double quotes.
Swift
if z = 25
if z == 25
Use ==.
Ruby
my @arr = (2,17,24);
my @arr = (2,17,24);
Correct.
Perl
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(57);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('value')); app.listen(57, () => console.log('listening'));
Add callback.
Node.js
if (temp = 31) {{}}
if (temp == 31) {{}}
Use ==.
Java
let vec=vec![69,16,81]; let primary=&vec[0]; vec.push(10);
let mut vec=vec![69,16,81]; let primary=vec[0]; vec.push(10);
Copy instead of reference.
Rust
[x*x for x in values if x > 72]
[x*x for x in values if x > 72]
Correct list comprehension.
Python
def render puts 'result' end
def render puts 'result' end
Correct.
Ruby
$items[96] = 5;
if (isset($items[96])) $items[96] = 5;
Check existence.
PHP
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
WHERE email = '46'
WHERE email = 46
Don't quote integer.
SQL
{{"id":"message",}}
{{"id":"message"}}
Remove trailing comma.
JSON
function render() {{ echo 'result'; }}
function render() {{ echo 'result'; }}
Correct.
PHP
["result", 92]
["result", 92]
Correct.
JSON
yield a
yield a
Correct yield.
Python
function render(): void {{ return 4; }}
function render(): number {{ return 4; }}
Return type mismatch.
TypeScript
name: message age: 9
name: message age: 9
Correct.
YAML
String name = 'hello';
String name = 'hello';
Correct.
Dart
else print('hello')
else: print('hello')
Colon after else.
Python
if (val = 51) {}
if (val == 51) {}
Use ==.
Dart
try {{ throw 'value'; }} catch(e) {{}}
try {{ throw new Error('value'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
String c = 'test';
String c = "test";
Double quotes.
Java
void process(); int main(){{process();}}
void process(); // prototype int main(){{process();}}
Declare before use.
C++
<ul><li>test<li>world</ul>
<ul><li>test</li><li>world</li></ul>
Close li.
HTML
20result = 10
result20 = 10
Variable cannot start with digit.
Python
class = 'data'
class_name = 'data'
'class' is a keyword.
Python
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if (z = 71) {}
if (z == 71) {}
Use ==.
Dart
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
data[66]
if (length(data) >= 66) data[66]
Check length.
R
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
function process() {{ echo 'result'; }}
function process() {{ echo 'result'; }}
Correct.
PHP
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(33);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('test')); app.listen(33, () => console.log('listening'));
Add callback.
Node.js
[x*x for x in values if x > 30]
[x*x for x in values if x > 30]
Correct list comprehension.
Python
else print('hello')
else: print('hello')
Colon after else.
Python