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

Owner: Nobody
Requestors: cpan [at]

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

Subject: Weirdness with passing named to multi infixes
Download (untitled) / with headers
text/plain 1.1k
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␤␤»
Download (untitled) / with headers
text/plain 758b
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

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

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