New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when passing the same named argument twice using different aliases #3315
Comments
From mark@kli.org
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
|
From @smlsOn Mon, 13 Jan 2014 18:28:14 -0800, mark@kli.org wrote:
This bug is still present in This is Rakudo version 2017.08-104-g76f1d8970 |
The RT System itself - Status changed from 'new' to 'open' |
From @smlsOn Mon, 13 Jan 2014 18:28:14 -0800, mark@kli.org wrote:
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. 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 |
Migrated from rt.perl.org#120995 (status was 'open')
Searchable as RT120995$
The text was updated successfully, but these errors were encountered: