# Possible bug with KeyValuePattern and Optional

Bug introduced in 10.4, resolved in 11.0.0

I expect to get 0 on every line of output of this:

ClearAll[f];
f[KeyValuePattern@{}, x_: 1] := 0;

(*none of these match, all should*)
f[{"k" -> "v"}, 0]
f[<|"k" -> "v"|>, 1]
f[{"k" -> "v"}]
f[<|"k" -> "v"|>]

(*same problem with Optional in front*)
ClearAll[f];
f[x_: 1, KeyValuePattern@{}] := 0;
f[0, {"k" -> "v"}]
f[1, <|"k" -> "v"|>]
f[{"k" -> "v"}]
f[<|"k" -> "v"|>]

(*no problems without Optional[]*)
ClearAll[g];
g[KeyValuePattern@{}, x_] := 0;

g[{"k" -> "v"}, 0]
g[<|"k" -> "v"|>, 1]

(*no problems without KeyValuePattern*)
ClearAll[h];
h[{_Rule ...}, x_: 1] := 0;
h[Association[___], x_: 1] := 0;

h[{"k" -> "v"}, 0]
h[<|"k" -> "v"|>, 1]
h[{"k" -> "v"}]
h[<|"k" -> "v"|>]


but none of the f seem to match. The problem is apparently the appearance of Optional. g is the same as f except that it lacks an Optional argument and it matches fine.

{_Rule ...} and Association[___] should mean the same as KeyValuePattern@{}, but they work.

The problem is not the lacking of arguments given to KeyValuePattern -- it also fails when there are lots of arguments.

Can someone confirm this?

\$Version
"10.4.1 for Microsoft Windows (64-bit) (April 11, 2016)"

• Confirmed, looks like a bug. – Kuba Jul 5 '16 at 20:57
• This is fixed now – masterxilo Sep 13 '16 at 17:54