# New Ticket Created by Paweł Pabian # Please include the string: [perl #109218] # in the subject line of all future correspondence about this issue. # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=109218 >
Problem: [18:22] <bbkr> rakudo: class A { has $.x = 1; has $.y = $.x; }; class B is A { has $.x = 2; }; B.new.x.say # one should expect "2". however assignment to $.y in parent class broke it somehow. [18:22] <p6eval> rakudo 6eae67: OUTPUT«Any()» Discussion: [18:24] <jnthn> bbkr: $.x is *virtual*. [18:24] <jnthn> bbkr: And attributes are initialized top-down. [18:24] <jnthn> oh but...hm [18:25] * jnthn gets curious about what is going onthere [18:26] <jnthn> bbkr: I think I know what's going on. [18:27] <jnthn> bbkr: The short answer is that you should be using has $.y = $!x; [18:28] <jnthn> bbkr: The long answer is that your $.x call is virtual so it touches an attribute in the subclass, which we didn't initialize yet. Touching it results in a kind of auto-vivification. Then, when we get to applying the defaults, we see the attribute $!x in the subclass was already touched so don't re-initialize it. [18:28] <jnthn> bbkr: I don't actually consider it a bug BUT the fact we let you write $.x there and not at least warn is a bug. [18:29] <moritz> jnthn: I thought reading should never result in autoviv [18:29] <moritz> not even here, I'd say [18:29] <jnthn> moritz: It's not vivification per se. [18:29] <jnthn> moritz: It's that the REPR lazily generates the scalar container. [18:30] <jnthn> moritz: Touching $!x forces it to do so. The fact it's done so makes it consider the attribute "touched" and thus it won't get initialized. [18:31] <PerlJam> bbkr: it's part of that assignment isn't assignment things that you get with = on declarations [18:31] <jnthn> std: class C { has $.x; has $.y = $!x; } [18:31] <p6eval> std 47c76b3: OUTPUT«ok 00:01 109m» [18:32] <bbkr> jnthn: thanks for detailed explanation, i'm confused now if I should report lack of warning bug since STD says this construct is OK [18:33] <jnthn> bbkr: We should complain about the code you wrote at compile time. [18:33] <jnthn> bbkr: So please do file a ticket on that.