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

Compiler: Loses type information in lambda with generic return type #46956

Closed
btrautmann opened this issue Aug 20, 2021 · 2 comments
Closed

Compiler: Loses type information in lambda with generic return type #46956

btrautmann opened this issue Aug 20, 2021 · 2 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. P2 A bug or feature request we're likely to work on

Comments

@btrautmann
Copy link

btrautmann commented Aug 20, 2021

Dart SDK version: 2.13.3 (stable) (Wed Jun 9 12:44:44 2021 +0200) on "macos_x64"

We noticed this issue when migrating a part of our codebase to null safety. To reproduce, simply add this code to a working Flutter program:

Future<void> _testFunction(String testString) async {
  final route = MaterialPageRoute<String>(builder: (_) => Container());
  final result = await () async {
    return Navigator.of(context).push(route);
  }();
  _testFunction2(result);
  }

void _testFunction2(String? testString) {
  print('This worked!');
}

When flutter test is run or just running tests through the IDE, you will get this compilation error, even though the analyzer (as seen through VSCode in this case) does not complain:

lib/main.dart:60:20: Error: The argument type 'Object?' can't be assigned to the parameter type 'String?'.
 - 'Object' is from 'dart:core'.
    _testFunction2(result);

This can be fixed by changing

return Navigator.of(context).push(route);

to

return Navigator.of(context).push<String?>(route);

(by explicitly adding the type information to push()).

@mraleph mraleph added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Aug 23, 2021
@mraleph
Copy link
Member

mraleph commented Aug 23, 2021

seems like an inference difference between CFE and analyzer. /cc @johnniwinther @stefantsov

@johnniwinther johnniwinther added the P2 A bug or feature request we're likely to work on label Aug 23, 2021
@chloestefantsova
Copy link
Contributor

I'm working on the issue at https://dart-review.googlesource.com/c/sdk/+/211023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

4 participants