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

Error when using a role parameter to parameterize another role. #6506

Open
p6rt opened this issue Sep 9, 2017 · 4 comments
Open

Error when using a role parameter to parameterize another role. #6506

p6rt opened this issue Sep 9, 2017 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Sep 9, 2017

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

Searchable as RT132051$

@p6rt
Copy link
Author

p6rt commented Sep 9, 2017

From vittore.scolari@gmail.com

The following script

  role DataNo {
  method Blob() {
  my \T = uint8;
  say T;
  Blob[T].new;
  }
  }

  my DataNo $a = DataNo.new;
  say $a.Blob;

  role Data[​::T] {
  method Blob() {
  say T;
  Blob[T].new;
  }
  }

my Data[uint8] $b = Data[uint8].new;
say $b.Blob;

dies with error​:
concatenate requires a concrete string, but got null
  in any protect at gen/moar/stage2/NQPCORE.setting line 1033

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

From @smls

Although that particular error message seems to be specific to `Blob`, it also breaks with other parametric roles (such as `Array`), because the generic parameter T of the outer role seems to be passed through without being specialized first.

Shorter examples​:

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

  ➜ role R[​::T] { method a { Blob[T].new } }; say R[Int].a.perl;
  concatenate requires a concrete string, but got null
  in any protect at gen/moar/stage2/NQPCORE.setting line 1033
  in method a at <unknown file> line 1
  in block <unit> at <unknown file> line 1

Looks related to https://rt-archive.perl.org/perl6/Ticket/Display.html?id=131947 .

@p6rt
Copy link
Author

p6rt commented Sep 10, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt p6rt added the oo label Jan 5, 2020
@usev6
Copy link

usev6 commented Oct 7, 2023

This seems to work fine nowadays:

The original report:

$ ./rakudo-m -e 'role DataNo { method Blob() { my \T = uint8; say T; Blob[T].new } }; my DataNo $a = DataNo.new; say $a.Blob; role Data[::T] { method Blob() { say T; Blob[T].new } }; my Data[uint8] $b = Data[uint8].new; say $b.Blob'
(uint8)
Blob[uint8]:0x<>
(uint8)
Blob[uint8]:0x<>

The two shortened evaluations:

$ ./rakudo-m -e 'role R[::T] { method a { Array[T].new } }; say R[Int].a.raku'
Array[Int].new()
$ ./rakudo-m -e 'role R[::T] { method a { Blob[T].new } }; say R[Int].a.raku'
Could not instantiate role 'Blob':
Can only parameterize with native int types, not 'Int'.

The second one errors out for a valid reason -- it works with e.g. int:

$ ./rakudo-m -e 'role R[::T] { method a { Blob[T].new } }; say R[int].a.raku'
Blob[int].new()

Tagging "testneeded".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants