wrong_code
stringlengths
3
123
correct_code
stringlengths
3
155
explanation
stringclasses
101 values
language
stringclasses
26 values
$items[32] = 5;
if (isset($items[32])) $items[32] = 5;
Check existence.
PHP
object Product {{ def main(args: Array[String]) = println("output") }}
object Product {{ def main(args: Array[String]): Unit = println("output") }}
Add return type Unit.
Scala
fn baz() -> i32 {{ 91 }}
fn baz() -> i32 {{ 91 }}
Correct.
Rust
p {{ color: green }}
p {{ color: green; }}
Add semicolon.
CSS
arr[84]
if (arr.indices.contains(84)) arr[84]
Check index.
Kotlin
<center>info</center>
<div style='text-align:center;'>info</div>
Use CSS.
HTML
val temp: Int = 'output'
val temp: String = 'output'
Fix type.
Kotlin
local z = 83
local z = 83
Correct.
Lua
with open('data.txt') as file_handle: data = file_handle.read()
with open('data.txt') as file_handle: data = file_handle.read()
Correct.
Python
var x = 5; x = "hello"
var x = "hello"
Type mismatch.
Swift
$x = 5; print $x
$x = 5; print $x;
Missing semicolon.
Perl
if ($y = 1) {{}}
if ($y -eq 1) {{}}
Use -eq.
PowerShell
<input type='text' value='output'>
<input type='text' value='output' name='id'>
Add name attribute.
HTML
if (b = 84) {{}}
if (b == 84) {{}}
Use ==.
Kotlin
List<int> list = [1,2,3];
List<int> list = [1,2,3];
Correct.
Dart
int index = 'message';
String index = 'message';
Type mismatch.
Dart
if index > 60 puts 'info'
if index > 60 puts 'info' end
Add 'end'.
Ruby
UPDATE products SET email='test' WHERE email=50
UPDATE products SET email='test' WHERE email=50;
Add semicolon.
SQL
public static void main(String[] args) {{}}
public static void main(String[] args) {{}}
Correct.
Java
if val = 43
if val == 43
Use ==.
MATLAB
name: world age: 57
name: world age: 57
Correct.
YAML
value: data name: hello,
value: data name: hello
Remove comma.
YAML
let result = 99; let result = 51;
let result = 99; result = 51;
Duplicate declaration.
JavaScript
System.out.println('hello')
System.out.println('hello');
Add semicolon.
Java
32result = 10
result32 = 10
Variable cannot start with digit.
Python
let text = String::from("test"); let r=&text; text.push_str("!");
let mut text = String::from("test"); let r=&text; println!("{{}}", r); text.push_str("!");
Cannot mutate while borrowed.
Rust
<img src='test.jpg'>
<img src='test.jpg' alt='desc'>
Add alt text.
HTML
int[] items = new int[83]; items[83] = 5;
int[] items = new int[83]; if (83 < items.length) items[83] = 5;
Check bounds.
Java
let vec=vec![88,95,65]; let primary=&vec[0]; vec.push(50);
let mut vec=vec![88,95,65]; let primary=vec[0]; vec.push(50);
Copy instead of reference.
Rust
$x = 5; echo $x
$x = 5; echo $x;
Missing semicolon.
PHP
if item = 72
if item == 72
Use ==.
Ruby
$list[23]
if ($list.Count -gt 23) {{ $list[23] }}
Check bounds.
PowerShell
{{'status':'message'}}
{{"status":"message"}}
Use double quotes.
JSON
for (num in items)
for (num of items)
for...in iterates keys.
JavaScript
let b: number = 'test';
let b: string = 'test';
Fix type.
TypeScript
println('test')
println("test")
Double quotes.
Scala
echo 'output'
echo 'output';
Add semicolon.
PHP
x := 57
x := 57
Correct.
Go
yield bar
yield bar
Correct yield.
Python
if bar = 78 {{}}
if bar == 78 {{}}
Use ==.
Swift
SELECT COUNT(*) FROM products
SELECT COUNT(*) FROM products;
Missing semicolon.
SQL
'61' + 78
61 + 78
Avoid string coercion.
JavaScript
{{"id":"result" "value":31}}
{{"id":"result", "value":31}}
Add comma.
JSON
function compute(data:string){{return data;}} compute(89);
function compute(data:string){{return data;}} compute('test');
Pass correct type.
TypeScript
data(88)
if length(data) >= 88, data(88), end
Check length.
MATLAB
fmt.Println 'hello'
fmt.Println('hello')
Missing parentheses.
Go
if (z = 66) {{}}
if (z === 66) {{}}
Use === for equality.
JavaScript
if bar = 80
if bar == 80
Use ==.
Go
DELETE FROM orders WHERE name=49
DELETE FROM orders WHERE name=49;
Add semicolon.
SQL
<br></br>
<br>
Self-closing.
HTML
int main() {{ return 0; }}
int main() {{ return 0; }}
Correct.
C++
let data: number | null = null; data.toFixed(80);
let data: number | null = null; if(data!==null) data.toFixed(80);
Null check.
TypeScript
function test(bar) print(bar) end
function test(bar) print(bar) end
Correct.
Lua
assert item > 28
assert item > 28
Correct.
Python
<p>hello <b>test</p></b>
<p>hello <b>test</b></p>
Nest properly.
HTML
let temp = 'info'
let temp = "info"
Double quotes.
Swift
String y = 'value';
String y = "value";
Double quotes.
Java
raise 'output'
raise Exception('output')
Raise needs an exception class.
Python
var x int
var x int
Correct.
Go
y > 86 & a < 35
y > 86 and a < 35
Use 'and' not '&'.
Python
$count = 87; if ($count = 87) {{}}
$count = 87; if ($count == 87) {{}}
Use ==.
PHP
<table><tr><td>world<td>hello</tr></table>
<table><tr><td>world</td><td>hello</td></tr></table>
Close td.
HTML
process
process()
Add parentheses.
Swift
while read line; do echo $line; done < input.csv
while read line; do echo $line; done < input.csv
Correct.
Shell
if ($foo = 90)
if ($foo == 90)
Use ==.
Perl
String name = 'world';
String name = 'world';
Correct.
Dart
try {{ throw 'test'; }} catch(e) {{}}
try {{ throw new Error('test'); }} catch(e) {{}}
Throw Error objects.
JavaScript
WHERE email = '27'
WHERE email = 27
Don't quote integer.
SQL
var x = 2;
var x = 2;
Correct.
Dart
data == '83'
data === 83
Use strict equality.
JavaScript
h1 {{ font-size:42px color:red; }}
h1 {{ font-size:42px; color:red; }}
Add semicolon.
CSS
x = 5; if x > 3, disp('large'), end
x = 5; if x > 3, disp('large'), end
Correct.
MATLAB
let text1 = String::from("info"); let s2 = text1; println!("{{}}", text1);
let text1 = String::from("info"); let s2 = text1.clone(); println!("{{}}", text1);
Clone to avoid move.
Rust
[x*x for x in data if x > 26]
[x*x for x in data if x > 26]
Correct list comprehension.
Python
SELECT id email FROM users;
SELECT id, email FROM users;
Add comma.
SQL
if (foo = 22)
if (foo == 22)
Use ==.
Scala
const user:Person = {{name:'world'}};
const user:Person = {{name:'world', age:80}};
Add missing property.
TypeScript
SELECT * FROM items WHRE status=76;
SELECT * FROM items WHERE status=76;
Fix WHERE.
SQL
let mut val=92; let r1=&mut val; let r2=&mut val;
let mut val=92; {{ let r1=&mut val; }} let r2=&mut val;
Only one mutable borrow.
Rust
div {{ color=red; }}
div {{ color: red; }}
Use colon.
CSS
for i=1,30 do print(i) end
for i=1,30 do print(i) end
Correct.
Lua
let count = 22; count += 1;
let mut count = 22; count += 1;
Need mut to modify.
Rust
val index = 'hello'
val index = "hello"
Double quotes.
Kotlin
@media screen {{ body {{}} }}
@media screen {{ body {{}} }}
Correct.
CSS
switch(val){{ case 62: break; }}
switch(val){{ case 62: break; default: break; }}
Add default case.
Java
values.forEach(function(c) {{ console.log(c); }})
values.forEach((c) => {{ console.log(c); }})
Arrow functions are cleaner.
JavaScript
<a href='https://example.com' target='_blank'>
<a href='https://example.com' target='_blank' rel='noopener'>
Add rel for security.
HTML
class Item def method end end
class Item def method end end
Correct.
Ruby
class Item {{ int result; }} obj.result=5;
class Item {{ public int result; }} obj.result=5;
Make field public.
Java
List(33,10,53)
List(33,10,53)
Correct.
Scala
.User {{ color: #333; }}
.User {{ color: #333; }}
Correct.
CSS
my @arr = (39,98,87);
my @arr = (39,98,87);
Correct.
Perl
x <- 5; if (x > 3) print('large')
x <- 5; if (x > 3) print('large')
Correct.
R
echo value test
echo 'value test'
Quote to prevent splitting.
Shell
match x {{ 1 => {{}} }}
match x {{ 1 => {{}} _ => {{}} }}
Match must be exhaustive.
Rust
if (num) console.log('yes') else console.log('no')
if (num) console.log('yes'); else console.log('no');
Missing semicolon.
JavaScript
try: x = 1 / 0 except pass
try: x = 1 / 0 except Exception: pass
Specify exception type.
Python
console.log('result'
console.log('result')
Close parenthesis.
JavaScript
<div color=#333>
<div style='color:#333;'>
Use style attribute.
CSS
def render(): print('output')
def render(): print('output')
Indent function body.
Python