Skip to content

Error: The getter 'prop' isn't defined for the type 'Object'. #43505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vsevolod19860507 opened this issue Sep 21, 2020 · 2 comments
Closed

Error: The getter 'prop' isn't defined for the type 'Object'. #43505

vsevolod19860507 opened this issue Sep 21, 2020 · 2 comments
Labels
closed-as-intended Closed as the reported issue is expected behavior

Comments

@vsevolod19860507
Copy link

Is it a bug or a feature?

abstract class A {
  int prop;
}

class B {
  B(this.obj);

  Object obj;

  void meth1(Object obj) {
    if (obj is A) {
      print(obj.prop); // Ok.
    }
  }

  void meth2() {
    if (obj is A) {
      print(obj.prop); // Error: The getter 'prop' isn't defined for the type 'Object'.
    }
  }
}
@eernstg
Copy link
Member

eernstg commented Sep 21, 2020

Instance variables cannot soundly be promoted (so obj doesn't get the type A in the if), because they can be overridden by a getter that could return a different object each time it is invoked. It is being debated whether we should allow an unsound mechanism (so each access would be checked dynamically), or maybe support easy introduction of a fresh variable whose initial value is the value of the instance variable.

A good place to start is dart-lang/language#1187.

@eernstg eernstg added the closed-as-intended Closed as the reported issue is expected behavior label Sep 21, 2020
@eernstg eernstg closed this as completed Sep 21, 2020
@vsevolod19860507
Copy link
Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-as-intended Closed as the reported issue is expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants