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

Weirdness with passing named to multi infixes #5073

Open
p6rt opened this issue Jan 25, 2016 · 3 comments
Open

Weirdness with passing named to multi infixes #5073

p6rt opened this issue Jan 25, 2016 · 3 comments

Comments

@p6rt
Copy link

p6rt commented Jan 25, 2016

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

Searchable as RT127359$

@p6rt
Copy link
Author

p6rt commented Jan 25, 2016

From @zoffixznet

In the first example blow, passing a named "foo" argument after a comma generates the "Unexpected named param passed..." warning and the $foo variable inside my multi is empty. Note that "meow" *was* printed, showing my custom sub was indeed called.

In the second example, we did not use a comma before the named "foo" argument; we're still getting the "Unexpected param" warning, but now our multi is not called.

Expected behaviour for both cases is our defined multi is called and the :foo argument is passed in as the named $foo parameter.

<ZoffixWin> m​: multi sub infix​:<+> (Int​:D $a, Int​:D $b, :$foo) {say "meow <$foo>"}; say say 42 + 1, :foo<42>;
<camelia> rakudo-moar d67cb0​: OUTPUT«Use of uninitialized value $foo of type Any in string context␤Any of .^name, .perl, .gist, or .say can stringify undefined things, if needed. in sub infix​:<+> at /tmp/OT3Cjm5qF9 line 1␤meow <>␤Unexpected named parameter 'foo' passed␤ in block <un…»
<ZoffixWin> m​: multi sub infix​:<+> (Int​:D $a, Int​:D $b, :$foo) {say "meow <$foo>"}; say 42 + 1 :foo<42>;
<camelia> rakudo-moar d67cb0​: OUTPUT«Unexpected named parameter 'foo' passed␤ in block <unit> at /tmp/0eAa6uTt5N line 1␤␤»

@p6rt
Copy link
Author

p6rt commented Jan 25, 2016

From @skids

Not sure the first behavior is a bug, as optional nameds may not be considered in multidispatch,
though the design docs spread this information all over the place so it's hard to tell.

Though, not generating an ambiguous error would be a bug, probably​:
$ perl6 -e 'multi sub a ($) { "nonamed".say }; multi sub a ($, :$foo) { $foo.say }; a(42); a(42, :foo(3))'
(Any)
3

Using a required named parameter​:
$ perl6 -e 'multi sub a ($) { "nonamed".say }; multi sub a ($, :$foo!) { $foo.say }; a(42); a(42, :foo(3))'
nonamed
3

So this should probably work, but does not​:
$ perl6 -e 'multi sub infix​:<+> (Int​:D $a, Int​:D $b, :$foo!) { $foo.say; $a + $b }; (42 + 1 :foo("OHAI")).perl.say;'
Unexpected named parameter 'foo' passed
  in block <unit> at -e line 1

@p6rt
Copy link
Author

p6rt commented Jan 25, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant