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

[extension types/analyzer] The receiver can't be null false negative on extension type typed values? #56759

Open
modulovalue opened this issue Sep 20, 2024 · 1 comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@modulovalue
Copy link
Contributor

Consider:

void main() {
  const Foo a = Foo(0);
  const int b = 0;
 
  a?.toString();
// The receiver can't be null, so the null-aware operator '?.' is unnecessary.
// v
  b?.toString();
}

extension type const Foo(int i) {}

b?.toString(); causes the analyzer to emit a The receiver can't be null, so the null-aware operator '?.' is unnecessary. diagnostic, but it looks to me like a?.toString(); could also be annotated with a similar diagnostic.

@dart-github-bot
Copy link
Collaborator

Summary: The analyzer incorrectly fails to detect that a null-aware operator is unnecessary for an extension type (Foo) when it should, as it does for a regular type (int). This suggests a potential false negative in the analyzer's null-aware operator analysis for extension types.

@dart-github-bot dart-github-bot added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants