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

Potentially spurious static type computation in the Analyzer #56963

Open
chloestefantsova opened this issue Oct 25, 2024 · 4 comments
Open

Potentially spurious static type computation in the Analyzer #56963

chloestefantsova opened this issue Oct 25, 2024 · 4 comments
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. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@chloestefantsova
Copy link
Contributor

Consider the following code:

extension on int? {
  int? operator+(int? other) {
    if (this != null && other != null) {
      return this! + other;
    } else {
      return null;
    }
  }
}

int test(int? x) {
  return ++x ?? 10;
}

The expected static type of ++x is int?, given the return type of operator+. However, the Analyzer reports the following warning:

warning - qwerty.dart:12:17 - The left operand can't be null, so the right operand is never executed. Try removing the operator and the right operand. - dead_null_aware_expression
@chloestefantsova chloestefantsova added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Oct 25, 2024
@chloestefantsova chloestefantsova changed the title Potentially spurrious Potentially spurious static type computation in the Analyzer Oct 25, 2024
@chloestefantsova
Copy link
Contributor Author

/cc @eernstg @sgrekhov

@adenes
Copy link

adenes commented Oct 26, 2024

I hope you don't mind me chiming in. I did some debugging and it seems this is where the nullability from int? gets lost: https://github.com/dart-lang/sdk/blob/main/pkg/analyzer/lib/src/dart/resolver/prefix_expression_resolver.dart#L231-L232

@bwilkerson
Copy link
Member

I hope you don't mind me chiming in.

No, we don't mind. We welcome all contributions. Thanks for digging into this and letting us know what you found!

@adenes
Copy link

adenes commented Oct 31, 2024

@srawlins srawlins added P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) analyzer-spec Issues with the analyzer's implementation of the language spec labels Nov 4, 2024
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. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants