6

That seems to be the case:

class Foo { has $!bar }; say Foo.new( :3bar ).perl # OUTPUT: «Foo.new␤» 

Documentation says it's implementation dependent, but I wonder if this actually makes sense.

jjmerelo
  • 22,578
  • 8
  • 40
  • 86

1 Answers1

9

The .perl output is correct. Foo.new( :3bar ) does not do what you think. If you add a method bar() { $!bar }, you'll notice that the private attribute $!bar did not get set:

class Foo {
    has $!bar;
    method bar() { $!bar }
}
say Foo.new( :3bar ).bar;   # (Any)
say Foo.new( :3bar ).perl;  # Foo.new

The named parameter :3bar (aka bar => 3) is silently ignored, because there is no public attribute with the name bar.

If you want it to complain about this situation, then maybe https://modules.raku.org/dist/StrictNamedArguments is something for you.

Elizabeth Mattijsen
  • 25,654
  • 3
  • 75
  • 105
  • 1
    the link is broken - it needs to point to either https://modules.perl6.org/dist/StrictNamedArguments:github:Claudio%20Ramirez (which redirects to github) or https://modules.perl6.org/search/?q=StrictNamedArguments – Christoph Feb 26 '19 at 17:17