Skip to content

Type promoting local variables on conditional member access #60015

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
FMorschel opened this issue Jan 30, 2025 · 1 comment
Closed

Type promoting local variables on conditional member access #60015

FMorschel opened this issue Jan 30, 2025 · 1 comment
Labels
closed-duplicate Closed in favor of an existing report legacy-area-analyzer Use area-devexp instead.

Comments

@FMorschel
Copy link
Contributor

I could not find another issue related so I'll open this one but if I missed it please let me know.

When we have the following code:

void foo() {
  int? value1 = bar();
  int? value2 = bar();

  if (value1 != null && value1.isOdd) {
    value1.isOdd; // No problem
  }

  if (value2?.isOdd ?? false) {
    value2.isOdd; // This still triggers unchecked_use_of_nullable_value but we know it is not null anymore
  }
}

int? bar() => 0;

I feel like for local variables, when we have ? just after them, we could promote them to non-nulls if the following expression is constant (like true/false). I'm unsure of this when the following expression is not constant but if someone smarter than me can come up with a reasonable line of thinking to enhance this I will not complain.

@FMorschel FMorschel added the legacy-area-analyzer Use area-devexp instead. label Jan 30, 2025
@eernstg
Copy link
Member

eernstg commented Jan 30, 2025

See dart-lang/language#1224.

@lrhn lrhn added the closed-duplicate Closed in favor of an existing report label Jan 30, 2025
@lrhn lrhn closed this as completed Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report legacy-area-analyzer Use area-devexp instead.
Projects
None yet
Development

No branches or pull requests

3 participants