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

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

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



Subject: [BUG] typed hashes and metaops and slots, oh my, in Rakudo
Date: Thu, 16 May 2013 23:23:26 +0200
To: rakudobug [...] perl.org
From: Carl Mäsak <cmasak [...] gmail.com>
Download (untitled) / with headers
text/plain 2.2k
<lizmat> r: https://gist.github.com/lizmat/5594924 <camelia> rakudo 570d1d: OUTPUT«("Foo::Bar" => {"perl6" => {}}).hash␤Nominal type check failed for parameter 'lhs'; expected Any but got Mu instead␤ in sub METAOP_TEST_ASSIGN:<//> at src/gen/CORE.setting:13798␤ in sub module2stash at /tmp/_BTgCQ8SZ_:15␤ in block at /tmp/_BTgCQ8SZ_:22␤␤»… <lizmat> I'm stumped, haven't been able to simplify this down further :-( <masak> r: (my %h{Any} of Hash){Any} //= my % <camelia> rakudo 570d1d: OUTPUT«Nominal type check failed for parameter 'lhs'; expected Any but got Mu instead␤ in sub METAOP_TEST_ASSIGN:<//> at src/gen/CORE.setting:13798␤ in block at /tmp/QD7khTjRjR:1␤␤» <masak> this is as golf'd as I can get it. <lizmat> r: my $froms= do { my %h{Any} of Hash; %h }; $froms<a> //= do { my %h{Any} of Hash; %h }; # my golf <camelia> rakudo 570d1d: OUTPUT«Nominal type check failed for parameter 'lhs'; expected Any but got Mu instead␤ in sub METAOP_TEST_ASSIGN:<//> at src/gen/CORE.setting:13798␤ in block at /tmp/773hQw7_T5:1␤␤» <masak> I think that makes it fairly clear that something is Wrong, at least. <lizmat> seems to me the code generated isn't getting the left hand side passed to it if the destination is a non-existent hash value on the left <lizmat> r: my $froms= do { my %h{Any} of Hash; %h }; $froms<a>=Any; $froms<a> //= do { my %h{Any} of Hash; %h }; say $froms; # works <camelia> rakudo 570d1d: OUTPUT«("a" => {}).hash␤» <lizmat> adding a $h<key>=Any apparently creates a container that //= can find <lizmat> r: my %h{Any}; %h<a> //= "a" #golfed shortest <camelia> rakudo 570d1d: OUTPUT«Nominal type check failed for parameter 'lhs'; expected Any but got Mu instead␤ in sub METAOP_TEST_ASSIGN:<//> at src/gen/CORE.setting:13798␤ in block at /tmp/Q3e_ebVOMA:1␤␤» <lizmat> r: my %h{Any}; %h<a>=Any; %h<a> //= "a" #golfed shortest <camelia> rakudo 570d1d: ( no output ) <lizmat> masak: rakudobug? * masak submits <lizmat> masak++ <lizmat> BTW, same goes for ||= and &&= <lizmat> also note that there is no problem if the hash is not typed <jnthn> Possible patch (please somebody else try it) for the lizmat++ bug: https://gist.github.com/jnthn/5595193 <lizmat> jnthn: I'll try that
Download (untitled) / with headers
text/plain 837b
The current behaviour is: $ perl6-m -e 'my %h{Any}; %h<a>=Any; %h<a> //= "a"; say %h.perl' Hash[Any,Any].new("a" => "a") $ perl6-m -e 'my %h{Any}; %h<a> //= "a"; say %h.perl' Hash[Any,Any].new("a" => "a") $ perl6-m -e 'my $froms= do { my %h{Any} of Hash; %h }; $froms<a>=Any; $froms<a> //= do { my %h{Any} of Hash; %h }; say $froms;' ## formerly marked as "works" Type check failed in assignment to '%h'; expected 'Hash' but got 'Any' in method assign_key at src/gen/m-CORE.setting:10342 in sub postcircumfix:<{ }> at src/gen/m-CORE.setting:2875 in block <unit> at -e:1 $ perl6-m -e 'my $froms= do { my %h{Any} of Hash; %h }; $froms<a> //= do { my %h{Any} of Hash; %h }; say $froms.perl' Hash[Any,Any].new("a" => Hash[Any,Any].new()) $ perl6-m -e '(my %h{Any} of Hash){Any} //= my %; say %h.perl' Hash[Any,Any].new(Any => {})
So is the current behavior good or bad?

On 2014-10-15 05:16:27, bartolin@gmx.de wrote:
Show quoted text
> The current behaviour is:
>
> $ perl6-m -e 'my %h{Any}; %h<a>=Any; %h<a> //= "a"; say %h.perl'
> Hash[Any,Any].new("a" => "a")
>
> $ perl6-m -e 'my %h{Any}; %h<a> //= "a"; say %h.perl'
> Hash[Any,Any].new("a" => "a")
>
> $ perl6-m -e 'my $froms= do { my %h{Any} of Hash; %h }; $froms<a>=Any;
> $froms<a> //= do { my %h{Any} of Hash; %h }; say $froms;' ## formerly
> marked as "works"
> Type check failed in assignment to '%h'; expected 'Hash' but got 'Any'
> in method assign_key at src/gen/m-CORE.setting:10342
> in sub postcircumfix:<{ }> at src/gen/m-CORE.setting:2875
> in block <unit> at -e:1
>
> $ perl6-m -e 'my $froms= do { my %h{Any} of Hash; %h }; $froms<a> //=
> do { my %h{Any} of Hash; %h }; say $froms.perl'
> Hash[Any,Any].new("a" => Hash[Any,Any].new())
>
> $ perl6-m -e '(my %h{Any} of Hash){Any} //= my %; say %h.perl'
> Hash[Any,Any].new(Any => {})




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