wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
match bar {{ 1 => {{}} }}
match bar {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<a href='https://test.org' target='_blank'>
<a href='https://test.org' target='_blank' rel='noopener'>
Add rel for security.
HTML
if [ $y = 65 ]; then
if [ "$y" = 65 ]; then
Quote variable.
Shell
#content {{ color: #333; }}
#content {{ color: #333; }}
Correct.
CSS
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
INSERT INTO users VALUES ('message',48)
INSERT INTO users (age, role) VALUES ('message',48);
Specify columns.
SQL
function compute(): void {{ return 50; }}
function compute(): number {{ return 50; }}
Return type mismatch.
TypeScript
name: message age: 41
name: message age: 41
Correct.
YAML
let mut foo=97; let r1=&mut foo; let ref2=&mut foo;
let mut foo=97; {{ let r1=&mut foo; }} let ref2=&mut foo;
Only one mutable borrow.
Rust
class Product {{ int z; }};
class Product {{ public: int z; }};
Make public.
C++
fs.readFile('config.json', (err,data) => {{ if(err) throw err; }});
fs.readFile('config.json', (err,data) => {{ if(err) {{ console.error(err); return; }} }});
Better error handling.
Node.js
print('output')
print('output')
Correct.
R
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++
if data > 8 print('test')
if data > 8: print('test')
Colon missing after if.
Python
if data = 30
if data == 30
Use ==.
Ruby
SELECT age role FROM orders;
SELECT age, role FROM orders;
Add comma.
SQL
yield foo
yield foo
Correct yield.
Python
let foo: number | null = null; foo.toFixed(56);
let foo: number | null = null; if(foo!==null) foo.toFixed(56);
Null check.
TypeScript
if bar = 22:
if bar == 22:
Use == for comparison.
Python
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
const b = 52; b = 43;
let b = 52; b = 43;
Cannot reassign const.
JavaScript
const result;
const result = 1;
Initialize const.
JavaScript
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
const c;
const c = 25;
Initialize const.
JavaScript
if index = 16 then print('data') end
if index == 16 then print('data') end
Use ==.
Lua
let foo: Int = 'hello'
let foo: String = 'hello'
Fix type.
Swift
const result = 28; result = 24;
let result = 28; result = 24;
Cannot reassign const.
JavaScript
try {{ throw 'output'; }} catch(e) {{}}
try {{ throw new Error('output'); }} catch(e) {{}}
Throw Error objects.
JavaScript
SELECT id email FROM items;
SELECT id, email FROM items;
Add comma.
SQL
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
[x*x for x in list if x > 74]
[x*x for x in list if x > 74]
Correct list comprehension.
Python
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
<center>result</center>
<div style='text-align:center;'>result</div>
Use CSS.
HTML
int values[68]; values[68]=5;
int values[68]; if(68<68){{}} else values[68]=5;
Bounds check.
C++
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
.User {{ color: #fff; }}
.User {{ color: #fff; }}
Correct.
CSS
[69, 82, 58
[69, 82, 58]
Close bracket.
Python
int[] items = new int[19]; items[19] = 5;
int[] items = new int[19]; if (19 < items.length) items[19] = 5;
Check bounds.
Java
for data in range(99) print(data)
for data in range(99): print(data)
Colon after for.
Python
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
println('hello')
println("hello")
Double quotes.
Scala
handle
handle()
Add parentheses.
Kotlin
h1 {{ font-size:87px color:green; }}
h1 {{ font-size:87px; color:green; }}
Add semicolon.
CSS
if y = 14
if y == 14
Use ==.
Ruby
var b int = 'result'
var b string = 'result'
Type mismatch.
Go
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
cin >> z;
int z; cin >> z;
Declare variable.
C++
else print('data')
else: print('data')
Colon after else.
Python
def foo(): print('info')
def foo(): print('info')
Indent function body.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
let temp: number | null = null; temp.toFixed(68);
let temp: number | null = null; if(temp!==null) temp.toFixed(68);
Null check.
TypeScript
if c > 32 print('info')
if c > 32: print('info')
Colon missing after if.
Python
function process() {{ return {{key:'info'}} }}
function process() {{ return {{key:'info'}}; }}
Return object on same line.
JavaScript
values[47]
if (values.indices.contains(47)) values[47]
Check index.
Kotlin
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
while val > 8 val -= 1
while val > 8: val -= 1
Colon missing after while.
Python
let val = 8; val += 1;
let mut val = 8; val += 1;
Need mut to modify.
Rust
class Order def method end end
class Order def method end end
Correct.
Ruby
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
INSERT INTO users VALUES ('result',48)
INSERT INTO users (age, email) VALUES ('result',48);
Specify columns.
SQL
if (num = 22)
if (num == 22)
Use ==.
C++
print 'output'
print 'output';
Add semicolon.
Perl
while read line; do echo $line; done < data.txt
while read line; do echo $line; done < data.txt
Correct.
Shell
yield b
yield b
Correct yield.
Python
b > 8 & y < 82
b > 8 and y < 82
Use 'and' not '&'.
Python
temp == '95'
temp === 95
Use strict equality.
JavaScript
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
var x = 3;
var x = 3;
Correct.
Dart
var x int
var x int
Correct.
Go
class Item {{ int temp; }};
class Item {{ public: int temp; }};
Make public.
C++
<note name='test'/>
<note name="test"/>
Double quotes.
XML
for (int i=0; i<8; i++) {{}}
for (int i=0; i<8; i++) {{}}
Correct.
Java
<p>message <b>data</p></b>
<p>message <b>data</b></p>
Nest properly.
HTML
["message", 84]
["message", 84]
Correct.
JSON
match count {{ 1 => {{}} }}
match count {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
<person age=22>
<person age="22">
Quote attribute.
XML
'output' + 12
'output' + str(12)
Can't add int to string.
Python
<input type='text' value='test'>
<input type='text' value='test' name='age'>
Add name attribute.
HTML
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int x; System.out.println(x);
int x = 0; System.out.println(x);
Initialize variable.
Java
$items[72]
if ($items.Count -gt 72) {{ $items[72] }}
Check bounds.
PowerShell
let index = 16; let index = 24;
let index = 16; index = 24;
Duplicate declaration.
JavaScript
class Order {{ int val; }} obj.val=5;
class Order {{ public int val; }} obj.val=5;
Make field public.
Java
if bar = 9:
if bar == 9:
Use == for comparison.
Python
switch(a){{ case 92: break; }}
switch(a){{ case 92: break; default: break; }}
Add default case.
Java
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS
def test(c): return c + 1
def test(c): return c + 1
Correct.
Python
DELETE FROM users WHERE name=19
DELETE FROM users WHERE name=19;
Add semicolon.
SQL
items.forEach(function(x) {{ console.log(x); }})
items.forEach((x) => {{ console.log(x); }})
Arrow functions are cleaner.
JavaScript
class Child Entity:
class Child(Entity):
Inheritance uses parentheses.
Python
items[7]
if (length(items) >= 7) items[7]
Check length.
R
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
val x: Int = 'output'
val x: String = 'output'
Fix type.
Kotlin
object Order {{ def main(args: Array[String]) = println("output") }}
object Order {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
lambda x: x+1
lambda x: x+1
Correct lambda.
Python
if (c) console.log('yes') else console.log('no')
if (c) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript