wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
var index int = 'message'
var index string = 'message'
Type mismatch.
Go
cin >> x cout << x;
cin >> x; cout << x;
Add semicolon.
C++
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
if bar = 80 then print('output') end
if bar == 80 then print('output') end
Use ==.
Lua
if result > 43 puts 'message'
if result > 43 puts 'message' end
Add 'end'.
Ruby
for (result in list)
for (result of list)
for...in iterates keys.
JavaScript
let text1 = String::from("data"); let text2 = text1; println!("{{}}", text1);
let text1 = String::from("data"); let text2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
class = 'world'
class_name = 'world'
'class' is a keyword.
Python
{{'value':'value'}}
{{"value":"value"}}
Use double quotes.
JSON
type MyType = string | number; let x: MyType = true;
type MyType = string | number; let x: MyType = 'hello';
Type not in union.
TypeScript
{ "name": "data" }
{ "name": "data" }
Correct.
JSON
const num;
const num = 9;
Initialize const.
JavaScript
list: - item1 - item2
list: - item1 - item2
Correct.
YAML
class User def method end end
class User def method end end
Correct.
Ruby
echo world world
echo 'world world'
Quote to prevent splitting.
Shell
int data = 'result';
String data = 'result';
Type mismatch.
Dart
name: hello name: world,
name: hello name: world
Remove comma.
YAML
var x = 61;
var x = 61;
Correct.
Dart
void main() {{ print('value') }}
void main() {{ print('value'); }}
Add semicolon.
Dart
["result", 54]
["result", 54]
Correct.
JSON
WHERE name = '71'
WHERE name = 71
Don't quote integer.
SQL
let mut data=24; let r1=&mut data; let r2=&mut data;
let mut data=24; {{ let r1=&mut data; }} let r2=&mut data;
Only one mutable borrow.
Rust
<img src='value.jpg'>
<img src='value.jpg' alt='desc'>
Add alt text.
HTML
[84, 46, 27
[84, 46, 27]
Close bracket.
Ruby
def process puts 'info' end
def process puts 'info' end
Correct.
Ruby
.Order {{ color: #333; }}
.Order {{ color: #333; }}
Correct.
CSS
int* person = nullptr; *person=5;
int* person = new int; *person=5;
Allocate memory.
C++
int[] items = new int[10]; items[10] = 5;
int[] items = new int[10]; if (10 < items.length) items[10] = 5;
Check bounds.
Java
<div><p>message</div></p>
<div><p>message</p></div>
Nest properly.
HTML
div {{ color=green; }}
div {{ color: green; }}
Use colon.
CSS
let num: Int = 'hello'
let num: String = 'hello'
Fix type.
Swift
let index: i32 = "hello";
let index: &str = "hello";
Type mismatch.
Rust
val z: Int = 'result'
val z: String = 'result'
Fix type.
Kotlin
if (foo = 26) {{}}
if (foo == 26) {{}}
Use ==.
Kotlin
let c: number | null = null; c.toFixed(61);
let c: number | null = null; if(c!==null) c.toFixed(61);
Null check.
TypeScript
render
render()
Add parentheses.
Swift
os.sqrt(16)
import os os.sqrt(16)
Import module first.
Python
<person name='hello'/>
<person name="hello"/>
Double quotes.
XML
println('info')
println("info")
Double quotes.
Scala
def process(index): return index + 1
def process(index): return index + 1
Correct.
Python
handle
handle()
Add parentheses.
Kotlin
$items[39] = 5;
if (isset($items[39])) $items[39] = 5;
Check existence.
PHP
if y > 77 print('message')
if y > 77: print('message')
Colon missing after if.
Python
<a href='https://demo.net' target='_blank'>
<a href='https://demo.net' target='_blank' rel='noopener'>
Add rel for security.
HTML
if data = 23 {{}}
if data == 23 {{}}
Use ==.
Swift
UPDATE items SET email='info' WHERE status=53
UPDATE items SET email='info' WHERE status=53;
Add semicolon.
SQL
class Product {{ int x; }};
class Product {{ public: int x; }};
Make public.
C++
if (count = 96) {}
if (count == 96) {}
Use ==.
Dart
arr(1)
if length(arr) >= 1, arr(1), end
Check length.
MATLAB
x := 26
x := 26
Correct.
Go
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
let item = 'data'
let item = "data"
Double quotes.
Swift
if ($z = 23) {{}}
if ($z -eq 23) {{}}
Use -eq.
PowerShell
raise 'world'
raise Exception('world')
Raise needs an exception class.
Python
System.out.println('value')
System.out.println('value');
Add semicolon.
Java
data.forEach(function(y) {{ console.log(y); }})
data.forEach((y) => {{ console.log(y); }})
Arrow functions are cleaner.
JavaScript
int &ref;
int x; int &ref = x;
Reference must be initialized.
C++
<?php // code ?>
<?php // code ?>
Correct.
PHP
if count = 10
if count == 10
Use ==.
Ruby
if [ $index = 99 ]; then
if [ "$index" = 99 ]; then
Quote variable.
Shell
if (x = 70) {{}}
if (x == 70) {{}}
Use ==.
Java
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
const result = 22; result = 55;
let result = 22; result = 55;
Cannot reassign const.
JavaScript
if (count = 51)
if (count == 51)
Use ==.
Scala
String x = 'output';
String x = "output";
Double quotes.
Java
<hr></hr>
<hr>
Self-closing.
HTML
switch(foo){{ case 69: break; }}
switch(foo){{ case 69: break; default: break; }}
Add default case.
Java
String name = 'hello';
String name = 'hello';
Correct.
Dart
<p>world <b>world</p></b>
<p>world <b>world</b></p>
Nest properly.
HTML
for (int i=0; i<76; i++) {{}}
for (int i=0; i<76; i++) {{}}
Correct.
Java
assert x > 72
assert x > 72
Correct.
Python
local count = 27
local count = 27
Correct.
Lua
$num = 77; if ($num = 77) {{}}
$num = 77; if ($num == 77) {{}}
Use ==.
PHP
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
<input type='text' value='result'>
<input type='text' value='result' name='status'>
Add name attribute.
HTML
function compute() {{ return {{key:'value'}} }}
function compute() {{ return {{key:'value'}}; }}
Return object on same line.
JavaScript
val bar = 3; bar = 4
var bar = 3; bar = 4
Use var for reassignment.
Scala
fn render() -> i32 {{ 8 }}
fn render() -> i32 {{ 8 }}
Correct.
Rust
cin >> c;
int c; cin >> c;
Declare variable.
C++
SELECT age role FROM products;
SELECT age, role FROM products;
Add comma.
SQL
for i=1,37 do print(i) end
for i=1,37 do print(i) end
Correct.
Lua
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(50);
const express = require('express'); const app = express(); app.get('/', (req,res) => res.send('info')); app.listen(50, () => console.log('listening'));
Add callback.
Node.js
print('info')
print('info')
Correct.
R
object Product {{ def main(args: Array[String]) = println("test") }}
object Product {{ def main(args: Array[String]): Unit = println("test") }}
Add return type Unit.
Scala
jwt.sign({{id:37}}, 'key');
jwt.sign({{id:37}}, 'key', {{expiresIn:'15m'}});
Add expiration.
Node.js
$list[23]
if ($list.Count -gt 23) {{ $list[23] }}
Check bounds.
PowerShell
if (a = 24) {{}}
if (a === 24) {{}}
Use === for equality.
JavaScript
h1 {{ font-size:61px color:#333; }}
h1 {{ font-size:61px; color:#333; }}
Add semicolon.
CSS
fmt.Println 'test'
fmt.Println('test')
Missing parentheses.
Go
{{'age':67, 'id' 95}}
{{'age':67, 'id':95}}
Colon missing.
Python
<div color=green>
<div style='color:green;'>
Use style attribute.
CSS
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
function handle() {{ echo 'info'; }}
function handle() {{ echo 'info'; }}
Correct.
PHP
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
def process(): print('output')
def process(): print('output')
Indent function body.
Python
{{"status":"result",}}
{{"status":"result"}}
Remove trailing comma.
JSON
match b {{ 1 => {{}} }}
match b {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
p {{ color: blue }}
p {{ color: blue; }}
Add semicolon.
CSS
disp('world')
disp('world')
Correct.
MATLAB
void foo(); int main(){{foo();}}
void foo(); // prototype int main(){{foo();}}
Declare before use.
C++