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

Type promotion doesn't work when a closure is used #45622

Closed
johnpryan opened this issue Apr 8, 2021 · 2 comments
Closed

Type promotion doesn't work when a closure is used #45622

johnpryan opened this issue Apr 8, 2021 · 2 comments

Comments

@johnpryan
Copy link
Contributor

johnpryan commented Apr 8, 2021

Result checkLottery(bool isLucky) {
  String? nullString;
  if (isLucky) {
    nullString = 'You win!';
  }

  if (nullString != null) {
    // Use this to fix:
    // var nonNullString = nullString;
    return () {
      return Result(nullString);
      //            ^ The argument type 'String?' can't be assigned to the parameter type 'String'.
    }();
  }

  return Result('You lose.');
}

@leafpetersen is there already an issue for this? I think this is called out in #44900

DartPad example

@johnpryan johnpryan changed the title Type promotion and closures Type promotion doesn't work when a closures is used Apr 8, 2021
@johnpryan johnpryan changed the title Type promotion doesn't work when a closures is used Type promotion doesn't work when a closure is used Apr 8, 2021
@eernstg
Copy link
Member

eernstg commented Apr 8, 2021

Cf. dart-lang/language#1247.

@ghost
Copy link

ghost commented Apr 14, 2021

This issue was moved by keertip to dart-lang/language#1582.

@ghost ghost closed this as completed Apr 14, 2021
This issue was closed.
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