Skip to content

Type promotion fails on local function call #47358

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
mnordine opened this issue Oct 2, 2021 · 2 comments
Closed

Type promotion fails on local function call #47358

mnordine opened this issue Oct 2, 2021 · 2 comments

Comments

@mnordine
Copy link
Contributor

mnordine commented Oct 2, 2021

I understand the following may be a tricky scenario for the analyzer, but just putting this here in case it can be fixed:

import 'dart:math' show Random;

void main() {
  int? x;
  if (Random().nextBool()) {
    x = 5;
  }
  
  if (x == null) return;
  
  void f() {
    var y = x * 2; // The operator '*' can't be unconditionally invoked because the receiver can be 'null'.
    print(y);
  }
  
  f();
}

f() is never called when x can be null.

This issue probably exists in some form, but I couldn't find it.

@asashour
Copy link
Contributor

asashour commented Oct 3, 2021

This is possibly dart-lang/language#1536

@mnordine
Copy link
Contributor Author

mnordine commented Oct 3, 2021

Thank you, I'd say it's close enough that I'll close in favor of that one.

@mnordine mnordine closed this as completed Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants