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

accessing a class attribute too early nils it/leaves it uninitialized #5667

Open
p6rt opened this issue Sep 13, 2016 · 6 comments
Open

accessing a class attribute too early nils it/leaves it uninitialized #5667

p6rt opened this issue Sep 13, 2016 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Sep 13, 2016

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

Searchable as RT129261$

@p6rt
Copy link
Author

p6rt commented Sep 13, 2016

From @skids

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)

@p6rt
Copy link
Author

p6rt commented Sep 13, 2016

From @geekosaur

On Mon, Sep 12, 2016 at 11​:40 PM, Brian S. Julin <
perl6-bugs-followup@​perl.org> wrote​:

$ 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

@p6rt
Copy link
Author

p6rt commented Sep 13, 2016

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

@p6rt
Copy link
Author

p6rt commented Sep 13, 2016

From @skids

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)␤»

@p6rt
Copy link
Author

p6rt commented Sep 13, 2016

From @zoffixznet

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)␤»

@p6rt
Copy link
Author

p6rt commented Sep 13, 2016

From @zoffixznet

And then this​:

<Zoffix> m​: class A { BEGIN my $.bar = 42; }; BEGIN A.bar; A.bar.say
<camelia> rakudo-moar ee4c96​: OUTPUT«42␤»

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

No branches or pull requests

1 participant