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

Owner: Nobody
Requestors: bri [at] abrij.org
Cc:
AdminCc:

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



Subject: accessing a class attribute too early nils it/leaves it uninitialized
Download (untitled) / with headers
text/plain 542b
A class attribute accessed too early in the compilation process will get nilled out, or possibly never initialized. $ perl6 -e 'class A { my $.bar = 42; }; class D { }; A.bar.say' # fine, working 42 $ perl6 -e 'class A { my $.bar = 42; }; class D { constant bar = A.bar.say; }; A.bar.say' (Any) (Any) $ perl6 -e 'class A { my $.bar = 42; }; class D { my $bar = A.bar.say; }; A.bar.say' 42 42 $ perl6 -e 'class A { my Int $.bar = 42; }; class D { constant bar = A.bar.say; }; A.bar.say' # Demonstrate it is typical Nil behavior (Int) (Int)
CC: bugs-bitbucket [...] rt.perl.org
From: Brandon Allbery <allbery.b [...] gmail.com>
Subject: Re: [perl #129261] accessing a class attribute too early nils it/leaves it uninitialized
To: perl6-compiler <perl6-compiler [...] perl.org>
Date: Mon, 12 Sep 2016 23:48:45 -0400
Download (untitled) / with headers
text/plain 599b
On Mon, Sep 12, 2016 at 11:40 PM, Brian S. Julin <perl6-bugs-followup@perl.org> wrote:
Show quoted text
$ perl6 -e 'class A { my $.bar = 42; }; class D { constant bar = A.bar.say; }; A.bar.say'
(Any)
(Any)

The first one is expected, as the bodies of class definitions run at compile time but initializers at run time. I don't know why the second one happens, though.

--
brandon s allbery kf8nh                               sine nomine associates
allbery.b@gmail.com                                  ballbery@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
Download (untitled) / with headers
text/plain 339b
Golf by TimToady: (11:54:47 PM) TimToady: m: class A { my $.bar = 42; }; class D { BEGIN A.bar.say; }; A.bar.say; (11:54:48 PM) camelia: rakudo-moar 22946e: OUTPUT«(Any)␤(Any)␤» (11:55:03 PM) TimToady: m: class A { my $.bar = 42; }; BEGIN A.bar.say; A.bar.say; (11:55:03 PM) camelia: rakudo-moar 22946e: OUTPUT«(Any)␤(Any)␤»
Download (untitled) / with headers
text/plain 256b
Slightly golfier (.say is not involved): <Zoffix> m: class A { my $.bar = 42; }; A.bar; A.bar.say <camelia> rakudo-moar ee4c96: OUTPUT«42␤» <Zoffix> m: class A { my $.bar = 42; }; BEGIN A.bar; A.bar.say <camelia> rakudo-moar ee4c96: OUTPUT«(Any)␤»
Download (untitled) / with headers
text/plain 130b
And then this: <Zoffix> m: class A { BEGIN my $.bar = 42; }; BEGIN A.bar; A.bar.say <camelia> rakudo-moar ee4c96: OUTPUT«42␤»


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