wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
match result {{ 1 => {{}} }}
match result {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<input type='text' value='test'>
<input type='text' value='test' name='id'>
Add name attribute.
HTML
'data' + 64
'data' + str(64)
Can't add int to string.
Python
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
System.out.println('data')
System.out.println('data');
Add semicolon.
Java
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
function render(): void {{ return 36; }}
function render(): number {{ return 36; }}
Return type mismatch.
TypeScript
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
while data > 65 data -= 1
while data > 65: data -= 1
Colon missing after while.
Python
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
fn compute() -> i32 {{ 68 }}
fn compute() -> i32 {{ 68 }}
Correct.
Rust
function handle(count) print(count) end
function handle(count) print(count) end
Correct.
Lua
baz
baz()
Add parentheses.
Kotlin
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(54);
const http = require('http'); http.createServer((req,res) => res.end('output')).listen(54);
Correct.
Node.js
[72, 34, 45
[72, 34, 45]
Close bracket.
Ruby
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
UPDATE users SET email='message' WHERE status=36
UPDATE users SET email='message' WHERE status=36;
Add semicolon.
SQL
h1 {{ font-size:4px color:#333; }}
h1 {{ font-size:4px; color:#333; }}
Add semicolon.
CSS
<ul><li>data<li>world</ul>
<ul><li>data</li><li>world</li></ul>
Close li.
HTML
<note><desc>info</desc><name>59</name></note
<note><desc>info</desc><name>59</name></note>
Add closing >.
XML
$data[51] = 5;
if (isset($data[51])) $data[51] = 5;
Check existence.
PHP
values[51]
if values.indices.contains(51) {{ values[51] }}
Check index.
Swift
var x = 5; x = true
var x = 5; x = 10
Type mismatch.
Kotlin
let item: Int = 'world'
let item: String = 'world'
Fix type.
Swift
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
const x = 67; x = 57;
let x = 67; x = 57;
Cannot reassign const.
JavaScript
console.log('value'
console.log('value')
Close parenthesis.
JavaScript
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
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
var x int
var x int
Correct.
Go
if [ $a = 42 ]; then
if [ "$a" = 42 ]; then
Quote variable.
Shell
var x = 37;
var x = 37;
Correct.
Dart
if (bar = 51) {}
if (bar == 51) {}
Use ==.
Dart
object Order {{ def main(args: Array[String]) = println("data") }}
object Order {{ def main(args: Array[String]): Unit = println("data") }}
Add return type Unit.
Scala
INSERT INTO products VALUES ('result',36)
INSERT INTO products (name, status) VALUES ('result',36);
Specify columns.
SQL
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
.Item {{ color: #fff; }}
.Item {{ color: #fff; }}
Correct.
CSS
with open('data.txt') as fh: data = fh.read()
with open('data.txt') as fh: data = fh.read()
Correct.
Python
[x*x for x in values if x > 88]
[x*x for x in values if x > 88]
Correct list comprehension.
Python
Product.save();
Product.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
WHERE email = '9'
WHERE email = 9
Don't quote integer.
SQL
$list[16]
if ($list.Count -gt 16) {{ $list[16] }}
Check bounds.
PowerShell
const person:Person = {{name:'output'}};
const person:Person = {{name:'output', age:40}};
Add missing property.
TypeScript
if (count = 57)
if (count == 57)
Use ==.
R
class Product {{ int c; }};
class Product {{ public: int c; }};
Make public.
C++
{{'status':18, 'id' 16}}
{{'status':18, 'id':16}}
Colon missing.
Python
var c int = 'hello'
var c string = 'hello'
Type mismatch.
Go
def compute(foo): return foo + 1
def compute(foo): return foo + 1
Correct.
Python
'46' + 7
46 + 7
Avoid string coercion.
JavaScript
JOIN orders ON users.id = orders.name
JOIN orders ON users.id = orders.name
Correct.
SQL
x := 7
x := 7
Correct.
Go
if c = 35
if c == 35
Use ==.
Go
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
function baz() {{ echo 'info'; }}
function baz() {{ echo 'info'; }}
Correct.
PHP
bar = hello
bar = 'hello'
Quote strings.
Python
if foo = 94 {{}}
if foo == 94 {{}}
Use ==.
Swift
if ($foo = 30)
if ($foo == 30)
Use ==.
Perl
let mut b=89; let ref1=&mut b; let ref2=&mut b;
let mut b=89; {{ let ref1=&mut b; }} let ref2=&mut b;
Only one mutable borrow.
Rust
jwt.sign({{id:45}}, 'password');
jwt.sign({{id:45}}, 'password', {{expiresIn:'30m'}});
Add expiration.
Node.js
z = 96
z=96
No spaces.
Shell
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
switch(result){{ case 77: break; }}
switch(result){{ case 77: break; default: break; }}
Add default case.
Java
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
int c = 'world';
String c = 'world';
Type mismatch.
Dart
<person age=73>
<person age="73">
Quote attribute.
XML
<center>hello</center>
<div style='text-align:center;'>hello</div>
Use CSS.
HTML
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(33);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('result')); app.listen(33, () => console.log('listening'));
Add callback.
Node.js
for (result in arr)
for (result of arr)
for...in iterates keys.
JavaScript
if (temp = 36) {{}}
if (temp == 36) {{}}
Use ==.
Kotlin
def foo puts 'hello' end
def foo puts 'hello' end
Correct.
Ruby
String temp = 'message';
String temp = "message";
Double quotes.
Java
87z = 10
z87 = 10
Variable cannot start with digit.
Python
int* p = nullptr; *p=5;
int* p = new int; *p=5;
Allocate memory.
C++
for i=1,27 do print(i) end
for i=1,27 do print(i) end
Correct.
Lua
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
List(21,21,21)
List(21,21,21)
Correct.
Scala
{{'age':'message'}}
{{"age":"message"}}
Use double quotes.
JSON
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
yield b
yield b
Correct yield.
Python
print 'hello'
print('hello')
Parentheses for function call.
Lua
<person name='info'/>
<person name="info"/>
Double quotes.
XML
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
<?php // code ?>
<?php // code ?>
Correct.
PHP
$count = 86; if ($count = 86) {{}}
$count = 86; if ($count == 86) {{}}
Use ==.
PHP
<div><p>world</div></p>
<div><p>world</p></div>
Nest properly.
HTML
{{"age":"result",}}
{{"age":"result"}}
Remove trailing comma.
JSON
assert z > 45
assert z > 45
Correct.
Python
class Child Model:
class Child(Model):
Inheritance uses parentheses.
Python
def compute(): print('data')
def compute(): print('data')
Indent function body.
Python
void bar(); int main(){{bar();}}
void bar(); // prototype int main(){{bar();}}
Declare before use.
C++
let bar = 63;
let bar = 63;
Correct.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
print 'info'
print('info')
print needs parentheses.
Python
my @arr = (29,31,49);
my @arr = (29,31,49);
Correct.
Perl