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

Testing an assignment against null does not promote the assigned variable (unchecked_use_of_nullable_value) #2583

Closed
Hixie opened this issue Oct 20, 2022 · 5 comments
Labels
flow-analysis Discussions about possible future improvements to flow analysis small-feature A small feature which is relatively cheap to implement.

Comments

@Hixie
Copy link

Hixie commented Oct 20, 2022

int? test() => null;

void main() {
  int? foo;
  while ((foo = test()) != null) {
    foo.toDouble(); // error • The method 'toDouble' can't be unconditionally invoked because the receiver can be 'null'
  }
}
@mraleph
Copy link
Member

mraleph commented Oct 21, 2022

likely a language issue, rather then tooling issue

/cc @eernstg @stereotype441

@stereotype441
Copy link
Member

Yeah, flow analysis doesn't handle this. It does seem like it would be good if it did.

I'm going to move this issue to the language repo and tag it as a potential future flow analysis improvement to consider.

@stereotype441 stereotype441 transferred this issue from dart-lang/sdk Oct 21, 2022
@stereotype441 stereotype441 added small-feature A small feature which is relatively cheap to implement. flow-analysis Discussions about possible future improvements to flow analysis labels Oct 21, 2022
@srawlins
Copy link
Member

I think this is essentially #1420?

@stereotype441
Copy link
Member

@srawlins good catch. It looks like #1420 covers multiple suggestions, and #1844 specifically covers this request, so I'll mark as a duplicate of #1844.

@stereotype441
Copy link
Member

Duplicate of #1844.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flow-analysis Discussions about possible future improvements to flow analysis small-feature A small feature which is relatively cheap to implement.
Projects
None yet
Development

No branches or pull requests

4 participants