Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Overriding a field with a getter (but no setter) causes a runtime error #380

Closed
vsmenon opened this issue Nov 2, 2015 · 2 comments
Closed

Comments

@vsmenon
Copy link
Contributor

vsmenon commented Nov 2, 2015

This is another manifestation of overriding fields (see #52). This particular one is a common pattern in Angular.

class A {
  String x = "hello";
}

class B extends A {
  String get x => "world";
}

void main() {
  var a = new B();
  print(a.x);
}

At runtime, this triggers:

Uncaught TypeError: Cannot set property x of [object Object] which has only a getter

in A's constructor.

@jmesserly
Copy link
Contributor

Yeah, as noted in #52 (comment), the only pattern we support is using a field to implement a getter/setter. You can never override a field, either with another field, or a getter/setter (those two cases are the same underlying issue.)

So, as discussed in #52, we have two options: either it's an error and we need to patch Angular, because the current code doesn't work in Strong Mode, or we take a big codegen/readability hit on (at least) all public fields & some set of private fields.

@jmesserly
Copy link
Contributor

There's some more middle of the road options we could consider. I'll move discussion of that over to #52.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants