-
Notifications
You must be signed in to change notification settings - Fork 27
Overridden private fields trigger runtime error #370
Comments
@vsmenon -- that's an illegal field override with field, right? |
in other words, is this a dupe of #52 |
Right, if we statically disallow, we could make this a "won't fix". |
Nice. I'll dupe it as the other bug covers either fix option. I think we're leaning towards restriction first. While runtime fix is pretty easy, it has some bad implications on the generated code. |
I'm hitting a different error if I change the override to a getter: class A {
int _x = 42;
}
class B extends A {
int get _x => 32;
}
main() {
var a = new B();
print(a._x);
} Error is:
|
We could statically disallow this as well though. |
good catch! I forgot if that was supposed to be supported or not :) does it work differently with public fields (I guess probably not)? |
Looking at the comments, it looks like we didn't intend to support overriding fields at all, even with getter/setter. (It doesn't interact well with separate compilation. Basically has the same issue.) I wonder if this works, though: class A {
int get _x => 42;
}
class B extends A {
int _x = 32;
}
main() {
var a = new B();
print(a._x);
} That one should work, but might not, because this code looks pretty fishy: FWIW, that string concat is semantically meaningless ... the string is only to help debugging. |
The following code:
generates this error:
The text was updated successfully, but these errors were encountered: