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

Owner: Nobody
Requestors: neven [at] luetic.de
Cc:
AdminCc:

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



To: rakudobug [...] perl.org
Subject: [BUG] shaped array attribute cannot be initialized from previously defined attributes
From: Neven Luetic <neven [...] luetic.de>
Date: Sun, 19 Feb 2017 17:53:37 +0100
Download (untitled) / with headers
text/plain 307b
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.
Date: Mon, 20 Feb 2017 05:15:47 +0000
Subject: Re: [perl #130817] [BUG] shaped array attribute cannot be initialized from previously defined attributes
From: Lloyd Fournier <lloyd.fourn [...] gmail.com>
To: perl6-compiler [...] perl.org, bugs-bitbucket [...] rt.perl.org
Download (untitled) / with headers
text/plain 1.1k
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-followup@perl.org> wrote:
Show quoted text
# 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.


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