Skip to content
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

Open
p6rt opened this issue Jan 14, 2014 · 4 comments
Open

Error when passing the same named argument twice using different aliases #3315

p6rt opened this issue Jan 14, 2014 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jan 14, 2014

Migrated from rt.perl.org#120995 (status was 'open')

Searchable as RT120995$

@p6rt
Copy link
Author

p6rt commented Jan 14, 2014

From mark@kli.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.

 

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From @smls

On Mon, 13 Jan 2014 18​:28​:14 -0800, mark@​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

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.

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From @smls

On Mon, 13 Jan 2014 18​:28​:14 -0800, mark@​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

@p6rt p6rt added the at_larry label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant