Skip to content
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

[analyzer] An external private field is erroneously promoted #53426

Closed
sgrekhov opened this issue Sep 5, 2023 · 3 comments
Closed

[analyzer] An external private field is erroneously promoted #53426

sgrekhov opened this issue Sep 5, 2023 · 3 comments
Assignees
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on

Comments

@sgrekhov
Copy link
Contributor

sgrekhov commented Sep 5, 2023

The code below produces an error in CFE but no error is reported in the analyzer

// SharedOptions=--enable-experiment=inference-update-2

class C {
  external final int? _x;

  void test() {
    if (_x is int) {
      _x.isOdd; // CFE. Error: Property 'isOdd' cannot be accessed on 'int?' because it is potentially null.
    }
  }
}

main() {
  C().test();
}

Seems that private fields promotion works here but it shouldn't. An external field declaration is effectively an external getter and setter. Nothing guarantees that it will return the same value if read twice, so it must not promote.

See #53419

@sgrekhov sgrekhov added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Sep 5, 2023
@stereotype441
Copy link
Member

I'll work on this.

@stereotype441 stereotype441 self-assigned this Sep 5, 2023
@sgrekhov
Copy link
Contributor Author

@stereotype441 the following test is still failing in CFE and Analyzer

class A {
  void foo() {}
}

class C<T> {
   external final T _x;

  void test() {
    if (_x is A) {
      _x.foo(); // Ok
//       ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
    }
  }
}

main() {
  C c = C();
  if (c._x is A) {
    c._x.foo(); // No expected error
//       ^^^^^
// [analyzer] unspecified
// [cfe] unspecified
  }
  c.test();
}

@sgrekhov sgrekhov reopened this Sep 11, 2023
@srawlins srawlins added P2 A bug or feature request we're likely to work on analyzer-spec Issues with the analyzer's implementation of the language spec labels Sep 11, 2023
@stereotype441
Copy link
Member

The failure mentioned in #53426 (comment) was addressed by dart-lang/co19#2309.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

3 participants