Skip to content

Dart 1.23 (strong mode) can not infer the type well #29437

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
tomyeh opened this issue Apr 24, 2017 · 6 comments
Closed

Dart 1.23 (strong mode) can not infer the type well #29437

tomyeh opened this issue Apr 24, 2017 · 6 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). language-strong-mode-polish stable-patch-candidate

Comments

@tomyeh
Copy link

tomyeh commented Apr 24, 2017

With the following code:

const dur = const Duration(seconds: 10);
final val = dur.inSeconds;

Dart 1.23 (dartanalyzer) said "hint • The type of 'val' can't be inferred because of the use of the instance getter 'inSeconds'"

Note: there is no such issue in Dart 1.22.1

@mit-mit
Copy link
Member

mit-mit commented Apr 24, 2017

@floitschG language or analyzer issue?

@anders-sandholm anders-sandholm added legacy-area-analyzer Use area-devexp instead. area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Apr 24, 2017
@bwilkerson bwilkerson removed the legacy-area-analyzer Use area-devexp instead. label Apr 24, 2017
@bwilkerson
Copy link
Member

I believe that analyzer is implementing the specification correctly.

@mit-mit
Copy link
Member

mit-mit commented Apr 24, 2017

But the implementation changed in 1.23 (the original bug text says it worked in 1.22.1)?

@leafpetersen
Copy link
Member

Strong mode top level inference restrictions (#28218) were incrementally rolled out in 1.23 (note that we issue a hint not an error). These will become errors in 1.24.

@tomyeh
Copy link
Author

tomyeh commented Apr 25, 2017

Sorry, I don't get it. Does it mean I have to specify the type explicitly even though it can be inferred from the expression? And, this restriction is only applied to top-level variables, while local variables has no such limitation?

@leafpetersen
Copy link
Member

We've rolled back the proposed restrictions to top level inference. This should work again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). language-strong-mode-polish stable-patch-candidate
Projects
None yet
Development

No branches or pull requests

5 participants