tobyink/p5-type-tiny

If hash is passed as a list, and has duplicate keys, receive "Wrong number of parameters; got <x>"

mvsjes2 opened this issue · 1 comments

I sometimes pass a hash to a sub and override existing keys with new ones:

my %args = (x => 1, y => 2);
call(%args, y => 3);     # ends up being [ 'x', 1, 'y', 2, 'y', 3]

This used to work pre V2, but now the checks for the number of args anticipated seems to appear nearer the beginning.

say "Type::Params version: $Type::Params::VERSION";
my $check = compile_named(test_string => Str);
$check->(test_string => "hello");
$check->(test_string => "hello", test_string => "world");

Older version runs ok:

Type::Params version: 1.008001

Newer version dies:

Type::Params version: 2.000001
Wrong number of parameters; got 4 at /home/robin/bin/ttt line 15.

Is it possible to resolve the hash first before checking?

Your example is a reasonable thing to want to do.

A workaround:

my %args = (x => 1, y => 2);
call({ %args, y => 3 });

I will fix this in a future release though.