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

typed hashes and metaops and slots, oh my, in Rakudo #3136

Open
p6rt opened this issue May 16, 2013 · 4 comments
Open

typed hashes and metaops and slots, oh my, in Rakudo #3136

p6rt opened this issue May 16, 2013 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented May 16, 2013

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

Searchable as RT118023$

@p6rt
Copy link
Author

p6rt commented May 16, 2013

From @masak

<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

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

From @usev6

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 => {})

@p6rt
Copy link
Author

p6rt commented Oct 15, 2014

@usev6 - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 3, 2017

From @AlexDaniel

So is the current behavior good or bad?

On 2014-10-15 05​:16​:27, bartolin@​gmx.de wrote​:

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 => {})

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant