I expected this wouldn't work because the attribute definition is parsed at
compile time when $!x and $!y aren't known. The error is definitely LTA.

You can do what you want like this:

class rect {
  has $.x;
  has $.y;

  has Array $.area .= new(:shape($!x,$!y))
}

say rect.new(x => 3,y => 4).area.shape[1] #-> 4

$.area has to be a $ attribute because @ will do array assignment which
will lose the shape of the RHS array (and we are not able to do := in the
default for attributes atm).

LL


On Mon, Feb 20, 2017 at 8:19 AM Neven Luetic <perl6-bugs-follo...@perl.org>
wrote:

> # New Ticket Created by  Neven Luetic
> # Please include the string:  [perl #130817]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=130817 >
>
>
>
> class rect {
>   has $.x;
>   has $.y;
>
>   has @.area[$!x;$!y];
> }
>
> my $rect = rect.new(x => 3, y => 5);
>
> gives:
> Cannot look up attributes in a VMNull type object
>   in block <unit> at t2.p6 line 6
>
> perl6 --version
> This is Rakudo version 2017.02-29-gb9332ae built on MoarVM version 2017.02
> implementing Perl 6.c.
>

Reply via email to