On Thu Oct 22 04:05:08 2009, masak wrote: > In Rakudo 4c248e5c, constants can no longer be used inside of classes. > > $ perl6 -e'class A { constant B = 5; has $!x = B }; A.new' > Null PMC access in isa() > [...] > $ perl6 -e'class A { constant B = 5; has $!x = A::B }; A.new' > Null PMC access in isa() > [...] > > I'm pretty sure this used to work before jnthn++'s merge. Which means > we probably don't have a spectest for this. > > Sadly, it's not possible to refer to constants-defined-outside-a-class > from within the class either. > > $ perl6 -e 'constant B = 5; class A { has $!x = B }; A.new' > Lexical 'B' not found > > Here's a clean workaround, for those who want something like constants > in a class: > > $ perl6 -e 'class A { sub B { 5 }; has $.x = B }; A.new.x.say' > 5
<jnthn> Out of curiosity, does a lexical instead of a constant work? <jnthn> How about an our-scoped variable? * masak tries <masak> jnthn: 'my' doesn't, 'our' works. <masak> 'my' produces the same error as 'constant'. I'll add that to the ticket. <jnthn> masak: OK. And since constants are package scoped, that probably gives us a pointer. <masak> nod. <jnthn> oh, my doesn't work? <jnthn> Hmm <jnthn> oh wait <jnthn> I think constants became our scoped in the spec *after* I implemented them. :-/ <jnthn> So they're probably still lexical. <masak> aye. <masak> that is consistent with the data. <jnthn> *nod* <jnthn> OK, so it looks like something to do with lexicals and attr initializers. <jnthn> Maybe we attach the initializer blocks to the wrong lexical scope.