folks. So, I’ve came across this compilation error a while ago.. As there’s an easy fix and I didn’t find anything relevant at the time, I eventually let it go.
I just remembered it and I’m now wondering if this is really part of the language grammar (which I highly doubt) or if it’s a compiler bug. I’m being purely curious about this — it doesn’t really affect development, but it would be nice to see if any of you have seen this already.
package view {
import flash.display.Sprite;
public class Main extends Sprite {
private var _view:Sprite = new Sprite();
public function Main() {
this.test();
}
private function test():void {
trace(this.view.x, this.view.y);
//1178: Attempted access of inaccessible property x through a reference with static type view:Main.
//1178: Attempted access of inaccessible property y through a reference with static type view:Main.
//Note that I got this due to the package name.
//It runs just fine if I rename the package or getter.
}
public function get view():Sprite {
return this._view;
}
}
}
I’d say this is either a compiler bug or an inconsistency in the spec.
Quote from the chapter 11.1 Package namespace (I’d link directly, but the docs use frames):
Now, from the above, I gather that this line:
Shouldn’t be interpreted by the compiler as refering to the
viewpackage, since it seems to contradict this point — I’ll call it A):Because
this, unless I’m mistaken, is a runtime value.Then, if you use
thisthe ambiguity could be solved as your getter, I think, but according to this paragraph — let’s call it B), it won’t:So, if you don’t use
this, it’s clear from the spec thatview.xshould be interpreted as a reference to the defintion ofxin theviewpackage.If you explicitly say
this, there’s a contradiction between A) and B), as I see it. According to A) there should be no aliasing; but the aliasing is happening, it seems, because there’s a package name used on the left of a dot operator. So my guess is the compiler is not parsing the package in context, so to speak, just checking if any name on the left of a dot operator matches the name of a defined package.