Skip Menu |
Report information
Id: 79642
Status: resolved
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: masak <cmasak [at] gmail.com>
Cc:
AdminCc:

Severity: (no value)
Tag:
  • Bug
  • testneeded
Platform: (no value)
Patch Status: (no value)
VM: (no value)



Subject: [BUG] When a hash isn't bound to an optional %-sigilled parameter, something weird ends up in it in Rakudo
Date: Tue, 23 Nov 2010 01:05:50 +0100
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Download (untitled) / with headers
text/plain 746b
<masak> rakudo: sub foo($a, %h?) { bar($a, %h) }; sub bar($a, %h?) { say "alive!" }; foo(42) <p6eval> rakudo : OUTPUT«Method 'HOW' not found for invocant of class 'Hash'␤ in 'bar' at line 1 [...] <masak> rakudo: sub foo($a, %h?) { say %h.WHAT }; foo(42) <p6eval> rakudo : OUTPUT«Method 'WHAT' not found for invocant of class 'Hash'␤ in 'foo' at line 22:/tmp/qK5WsYzzEI␤ in main program body at line 22:/tmp/qK5WsYzzEI␤» * masak submits rakudobug <colomon> masak++ <masak> bug brought to you courtesy of a November being brought back from the Mostly Dead. Further experimenting reveals that the %h coming in through &foo claims to be a Hash, but it has no methods at all, so you can't do anything with it, not even pass it to &bar.
RT-Send-CC: perl6-compiler [...] perl.org
On Mon Nov 22 16:06:07 2010, masak wrote: Show quoted text
> <masak> rakudo: sub foo($a, %h?) { bar($a, %h) }; sub bar($a, %h?) { > say "alive!" }; foo(42) > <p6eval> rakudo : OUTPUT«Method 'HOW' not found for invocant of class > 'Hash'␤ in 'bar' at line 1 [...] > <masak> rakudo: sub foo($a, %h?) { say %h.WHAT }; foo(42) > <p6eval> rakudo : OUTPUT«Method 'WHAT' not found for invocant of class > 'Hash'␤ in 'foo' at line 22:/tmp/qK5WsYzzEI␤ in main program body at > line 22:/tmp/qK5WsYzzEI␤» > * masak submits rakudobug > <colomon> masak++ > <masak> bug brought to you courtesy of a November being brought back > from the Mostly Dead. > > Further experimenting reveals that the %h coming in through &foo > claims to be a Hash, but it has no methods at all, so you can't do > anything with it, not even pass it to &bar.
<masak> ah, here's a workaround: <masak> rakudo: sub foo($a, %h = {}) { bar($a, %h) }; sub bar($a, %h?) { say "alive!" }; foo(42) <p6eval> rakudo : OUTPUT«alive!␤» <masak> of course. * masak adds that to the ticket
RT-Send-CC: perl6-compiler [...] perl.org
Download (untitled) / with headers
text/plain 1.1k
On Mon Nov 22 16:06:07 2010, masak wrote: Show quoted text
> <masak> rakudo: sub foo($a, %h?) { bar($a, %h) }; sub bar($a, %h?) { > say "alive!" }; foo(42) > <p6eval> rakudo : OUTPUT«Method 'HOW' not found for invocant of class > 'Hash'␤ in 'bar' at line 1 [...] > <masak> rakudo: sub foo($a, %h?) { say %h.WHAT }; foo(42) > <p6eval> rakudo : OUTPUT«Method 'WHAT' not found for invocant of class > 'Hash'␤ in 'foo' at line 22:/tmp/qK5WsYzzEI␤ in main program body
at Show quoted text
> line 22:/tmp/qK5WsYzzEI␤» > * masak submits rakudobug > <colomon> masak++ > <masak> bug brought to you courtesy of a November being brought back > from the Mostly Dead. > > Further experimenting reveals that the %h coming in through &foo > claims to be a Hash, but it has no methods at all, so you can't do > anything with it, not even pass it to &bar.
Fixed: 16:35 < [Coke]> rakudo: sub foo($a, %h?) { bar($a, %h) }; sub bar($a, %h?) {say "alive!" }; foo(42) 16:35 -!- pothos_ is now known as pothos 16:35 <+p6eval> rakudo 88c5a5: OUTPUT«alive!␤» 16:35 < [Coke]> rakudo: sub foo($a, %h?) { say %h.WHAT }; foo(42) 16:36 <+p6eval> rakudo 88c5a5: OUTPUT«Hash()␤» Closable with tests. -- Will "Coke" Coleda
Now tested in S06-signature/optional.t.


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

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