Skip Menu |
Report information
Id: 120995
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: mark [at] kli.org
Cc:
AdminCc:

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: "Mark E. Shoulson" <mark [...] kli.org>
Date: Mon, 13 Jan 2014 21:28:05 -0500
Subject: Same argument present multiple times is okay with one name, not with two
To: rakudobug [...] perl.org
> 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

If nothing else, the error message is LTA.  But basically we're allowed to pass the same named parameter in twice if we use the same name, but not if we use different names.
Download (untitled) / with headers
text/plain 559b
On Mon, 13 Jan 2014 18:28:14 -0800, mark@kli.org wrote: Show quoted text
> > 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 > > If nothing else, the error message is LTA. But basically we're allowed > to pass > the same named parameter in twice if we use the same name, but not if > we use > different names.
This bug is still present in This is Rakudo version 2017.08-104-g76f1d8970 built on MoarVM version 2017.08.1-148-g1059eed1 implementing Perl 6.c.
Download (untitled) / with headers
text/plain 2.6k
On Mon, 13 Jan 2014 18:28:14 -0800, mark@kli.org wrote: Show quoted text
> > 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


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org