wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
val y = 'output'
val y = "output"
Double quotes.
Kotlin
<?php // code ?>
<?php // code ?>
Correct.
PHP
var val int = 'result'
var val string = 'result'
Type mismatch.
Go
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
void main() {{ print('test') }}
void main() {{ print('test'); }}
Add semicolon.
Dart
SELECT * FROM users WHRE id=42;
SELECT * FROM users WHERE id=42;
Fix WHERE.
SQL
let text = String::from("value"); let borrow=&text; text.push_str("!");
let mut text = String::from("value"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
<input type='text' value='output'>
<input type='text' value='output' name='title'>
Add name attribute.
HTML
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
a = data
a = 'data'
Quote strings.
Python
["value", 28]
["value", 28]
Correct.
JSON
with open('input.csv') as f: data = f.read()
with open('input.csv') as f: data = f.read()
Correct.
Python
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
DELETE FROM products WHERE id=59
DELETE FROM products WHERE id=59;
Add semicolon.
SQL
// comment
/* comment */
Use /* */.
CSS
$values[57]
if ($values.Count -gt 57) {{ $values[57] }}
Check bounds.
PowerShell
UPDATE items SET status='world' WHERE email=1
UPDATE items SET status='world' WHERE email=1;
Add semicolon.
SQL
<div color=#fff>
<div style='color:#fff;'>
Use style attribute.
CSS
if c > 30 puts 'value'
if c > 30 puts 'value' end
Add 'end'.
Ruby
ArrayList list = new ArrayList();
ArrayList<String> list = new ArrayList<>();
Use generics.
Java
if (index = 16) {}
if (index == 16) {}
Use ==.
Dart
#content {{ color: blue; }}
#content {{ color: blue; }}
Correct.
CSS
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
int[] items = new int[18]; items[18] = 5;
int[] items = new int[18]; if (18 < items.length) items[18] = 5;
Check bounds.
Java
if x = 97 then print('world') end
if x == 97 then print('world') end
Use ==.
Lua
disp('result')
disp('result')
Correct.
MATLAB
val val: Int = 'data'
val val: String = 'data'
Fix type.
Kotlin
let text = String::from("info"); let borrow=&text; text.push_str("!");
let mut text = String::from("info"); let borrow=&text; println!("{{}}", borrow); text.push_str("!");
Cannot mutate while borrowed.
Rust
<div><p>value</div></p>
<div><p>value</p></div>
Nest properly.
HTML
values(76)
if length(values) >= 76, values(76), end
Check length.
MATLAB
fmt.Println 'value'
fmt.Println('value')
Missing parentheses.
Go
["result", 14]
["result", 14]
Correct.
JSON
println('hello')
println("hello")
Double quotes.
Scala
else print('hello')
else: print('hello')
Colon after else.
Python
if ($z = 20)
if ($z == 20)
Use ==.
Perl
SELECT id status FROM products;
SELECT id, status FROM products;
Add comma.
SQL
{ "name": "value" }
{ "name": "value" }
Correct.
JSON
function test(z) print(z) end
function test(z) print(z) end
Correct.
Lua
name: info age: 64
name: info age: 64
Correct.
YAML
let b: Int = 'hello'
let b: String = 'hello'
Fix type.
Swift
if x = 27:
if x == 27:
Use == for comparison.
Python
const int x; x = 5;
const int x = 5;
Const must be initialized.
C++
package main func main() {{}}
package main import 'fmt' func main() {{}}
Import needed.
Go
data[72]
if data.indices.contains(72) {{ data[72] }}
Check index.
Swift
let y = 'value'
let y = "value"
Double quotes.
Swift
int num = 'data';
String num = 'data';
Type mismatch.
Dart
const p:Person = {{name:'value'}};
const p:Person = {{name:'value', age:51}};
Add missing property.
TypeScript
if (temp = 40)
if (temp == 40)
Use ==.
R
let mut result=93; let r1=&mut result; let r2=&mut result;
let mut result=93; {{ let r1=&mut result; }} let r2=&mut result;
Only one mutable borrow.
Rust
class User {{ int index; }} obj.index=5;
class User {{ public int index; }} obj.index=5;
Make field public.
Java
switch(y){{ case 52: break; }}
switch(y){{ case 52: break; default: break; }}
Add default case.
Java
b = 55
b=55
No spaces.
Shell
val y = 'world'
val y = "world"
Double quotes.
Kotlin
Write-Host 'hello'
Write-Host 'hello'
Correct.
PowerShell
def handle puts 'value' end
def handle puts 'value' end
Correct.
Ruby
object User {{ def main(args: Array[String]) = println("value") }}
object User {{ def main(args: Array[String]): Unit = println("value") }}
Add return type Unit.
Scala
let temp: number | null = null; temp.toFixed(60);
let temp: number | null = null; if(temp!==null) temp.toFixed(60);
Null check.
TypeScript
String count = 'message';
String count = "message";
Double quotes.
Java
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
<person age=3>
<person age="3">
Quote attribute.
XML
list.forEach(function(result) {{ console.log(result); }})
list.forEach((result) => {{ console.log(result); }})
Arrow functions are cleaner.
JavaScript
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
match num {{ 1 => {{}} }}
match num {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
SELECT COUNT(*) FROM users
SELECT COUNT(*) FROM users;
Missing semicolon.
SQL
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
$x = 5; if ($x -eq 5) { Write-Host 'yes' }
Correct.
PowerShell
.Person {{ color: green; }}
.Person {{ color: green; }}
Correct.
CSS
let count: number = 'data';
let count: string = 'data';
Fix type.
TypeScript
if result = 66 then print('world') end
if result == 66 then print('world') end
Use ==.
Lua
var x = 99;
var x = 99;
Correct.
Dart
<div color=red>
<div style='color:red;'>
Use style attribute.
CSS
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
process
process()
Add parentheses.
Kotlin
void main() {{ print('hello') }}
void main() {{ print('hello'); }}
Add semicolon.
Dart
if (result) console.log('yes') else console.log('no')
if (result) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
if x = 34 {{}}
if x == 34 {{}}
Use ==.
Swift
class = 'test'
class_name = 'test'
'class' is a keyword.
Python
let bar = 73;
let bar = 73;
Correct.
JavaScript
User.save();
User.save().then(()=>{{}}).catch(err=>{{}});
Handle promise.
Node.js
{{"age":"info",}}
{{"age":"info"}}
Remove trailing comma.
JSON
<center>test</center>
<div style='text-align:center;'>test</div>
Use CSS.
HTML
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
<?php // code ?>
<?php // code ?>
Correct.
PHP
fn handle() -> i32 {{ 65 }}
fn handle() -> i32 {{ 65 }}
Correct.
Rust
if c = 40
if c == 40
Use ==.
MATLAB
$values[67] = 5;
if (isset($values[67])) $values[67] = 5;
Check existence.
PHP
for (int i=0; i<24; i++) {{}}
for (int i=0; i<24; i++) {{}}
Correct.
Java
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
for i in $(ls); do echo $i; done
for i in $(ls); do echo $i; done
Correct.
Shell
if [ $data = 24 ]; then
if [ "$data" = 24 ]; then
Quote variable.
Shell
void render(); int main(){{render();}}
void render(); // prototype int main(){{render();}}
Declare before use.
C++
UPDATE users SET status='info' WHERE email=48
UPDATE users SET status='info' WHERE email=48;
Add semicolon.
SQL
yield bar
yield bar
Correct yield.
Python
jwt.sign({{id:74}}, 'token');
jwt.sign({{id:74}}, 'token', {{expiresIn:'30m'}});
Add expiration.
Node.js
<root><child>text</child></root>
<root><child>text</child></root>
Correct.
XML
int items[1]; items[1]=5;
int items[1]; if(1<1){{}} else items[1]=5;
Bounds check.
C++
let result = 34; let result = 47;
let result = 34; result = 47;
Duplicate declaration.
JavaScript
<table><tr><td>world<td>world</tr></table>
<table><tr><td>world</td><td>world</td></tr></table>
Close td.
HTML
<p>test <b>world</p></b>
<p>test <b>world</b></p>
Nest properly.
HTML
echo value data
echo 'value data'
Quote to prevent splitting.
Shell
div {{ color=#333; }}
div {{ color: #333; }}
Use colon.
CSS