On Mon, 13 Jan 2014 18:28:14 -0800, m...@kli.org wrote:
> > sub f(:a(:b($x))) { say $x }
> sub f(Any :a(:b($x))) { ... }
> > f(:a("A"), :a("B"))
> B
> > f(:a("A"), :b("B"))
> Unexpected named parameter 'a' passed

I've had a look at `src/Perl6/Metamodel/BOOTSTRAP.nqp`, which is where the 
error message is thrown, and this is what seems to be happening:

---

1) A Hash called `$named_args` is created¹ from the incoming Capture, holding 
the named arguments that were passed.
If two different aliases were used on the calling side, then this Hash will 
obviously contain two separate entries.

2) The code then iterates over all parameters declared in the signature², and 
when it encounters a named parameter, it makes the list of the parameter's 
aliases available as a variable called `$named_names`³.

2b) It then iterates over this list of aliases, and for each one checks if 
`$named_args` contains an entry with that name. If so, it deletes⁴ that key 
from `$named_args` and stops looking⁵.

3) A it completed iterating over the whole signature, it checks⁶ whether 
there's anything left over in `$named_args`, and throws the exception quotes 
above if there is.

---

I am unsure how to properly fix this.

Removing the line `$j := $num_names;`⁵ which stops the code from looking 
further once it finds *one* alias of the named arameter for which the incoming 
Capture has a value, should make the error go away (untested)...

...but then multiple such arguments would override each other based on the 
order the aliases are declared in the signature, rather than the order in which 
the arguments are passed on the calling side... which would surely break user 
expectations.

The problem is that, AFAIK, the Capture doesn't even *remember* which order 
differently named arguments were passed in, because internally it stores them 
in a Hash.

So unless I'm missing something, this "bug" either requires invasive changes to 
Rakudo, or we need to accept it as something that can't be fixed and content 
ourselves with trying to improve the error message.

Tagging the issue with [@LARRY] to invite a decision from a core dev.

------
[1] 
https://github.com/rakudo/rakudo/blob/dfbd39b/src/Perl6/Metamodel/BOOTSTRAP.nqp#L649
[2] 
https://github.com/rakudo/rakudo/blob/dfbd39b/src/Perl6/Metamodel/BOOTSTRAP.nqp#L661
[3] 
https://github.com/rakudo/rakudo/blob/dfbd39b/src/Perl6/Metamodel/BOOTSTRAP.nqp#L749
[4] 
https://github.com/rakudo/rakudo/blob/dfbd39b/src/Perl6/Metamodel/BOOTSTRAP.nqp#L838
[5] 
https://github.com/rakudo/rakudo/blob/dfbd39b/src/Perl6/Metamodel/BOOTSTRAP.nqp#L839
[6] 
https://github.com/rakudo/rakudo/blob/dfbd39b/src/Perl6/Metamodel/BOOTSTRAP.nqp#L878

Reply via email to