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

Using a role parameter to constrain an uninitialized attribute, leaks a generic type object. #6463

Open
p6rt opened this issue Aug 22, 2017 · 2 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 22, 2017

Migrated from rt.perl.org#131947 (status was 'new')

Searchable as RT131947$

@p6rt
Copy link
Author

p6rt commented Aug 22, 2017

From @smls

This works​:

‎‎ ➜ role R [​::T] { has T $.a = T }; say R[Int].new.a;
‎‎ (Int)

But remove the explicit initializer `= T` (which should be redundant,
right?), and it blows up​:

‎‎ ➜ role R [​::T] { has T $.a }; say R[Int].new.a;
‎‎ No such method 'gist' for invocant of type 'T'
‎‎ in block <unit> at <unknown file> line 1

Looks like the automatic initializer for `$.a` leaves the type object of
the generic type T in the attribute, instead of letting it become the
concrete type Int.
Some introspection​:

  say R[Int].new.a.^name; # T
  say R[Int].new.a.HOW; # Perl6​::Metamodel​::GenericHOW.new

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From tomentiruran@gmail.com

role R[​::T] { has T $.r is rw }
(R)
R[Str].new.perl
No such method 'perl' for invocant of type 'T'
  in block <unit> at <unknown file> line 1

R[Str].new.r = Nil
No such method 'WHERE' for invocant of type 'T'

R[Str].new(​:r("r")).perl
R[Str].new(r => "r")

However, it works if $.r is initalised to T, which is presumably what the object creation should be doing.

--

perl6 -v
This is Rakudo version 2017.07 built on MoarVM version 2017.07
implementing Perl 6.c.
perl6 -V
distro​::auth=Apple Computer, Inc.
distro​::desc=2017-09-09T09​:21​:56.148447+08​:00
distro​::is-win=False
distro​::name=macosx
distro​::path-sep=​:
distro​::release=16G29
distro​::signature=
distro​::version=10.12.6
...

@p6rt p6rt added the oo 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