Skip to content

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

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

Open
ghost opened this issue Apr 14, 2021 · 1 comment
Open

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

ghost opened this issue Apr 14, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 14, 2021

@johnpryan commented on Apr 8, 2021, 12:12 AM UTC:

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

This issue was moved by keertip from dart-lang/sdk#45622.

@ghost
Copy link
Author

ghost commented Apr 14, 2021

@eernstg commented on Apr 8, 2021, 11:49 AM UTC:

Cf. dart-lang/language#1247.

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

0 participants