TSa Thomas.Sandlass-at-vts-systems.de |Perl 6| wrote:
class A { has $.foo = "A"; has $!bar = "A"; method blahh() { say $.foo ~ $!foo ~ $!bar; } } class B is A { has $.foo = "B"; has $!bar = "B"; } my $a = A.new; my $b = B.new; say $a.blahh; # prints AAA say $b.blahh; # prints BAA, right? Shouldn't there be a warning in B that $!B::bar overwrites $!A::bar without an accessor? And of course the example shows that $!foo in blahh is not derivation friendly. Or am I getting things wrong and there can be only one $!foo and $!bar in the namespace of the objects created from A and B? That is the declarations in B are superfluous if not outright wrong? Well, or they only affect the generated constructor and the storage location is shared? The latter would nicely contrast them to non twigil attributes in the form 'has $foo'.
A::!foo will be distinct from B::!foo. The accessor in B will override the accessor from A. I would not mind a warning, since the implementation knows what is going on being auto-generated. But in general, if you write methods that are accessors, separate from the backing data, the compiler can't tell what you meant and won't give any warning. --John