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 is not cast #49955

Closed
AlexanderFarkas opened this issue Sep 12, 2022 · 2 comments
Closed

Type is not cast #49955

AlexanderFarkas opened this issue Sep 12, 2022 · 2 comments

Comments

@AlexanderFarkas
Copy link

Screenshot 2022-09-12 at 23 14 19

Same without <dynamic,dynamic>
Screenshot 2022-09-12 at 23 14 34

But in that case it starts working
Screenshot 2022-09-12 at 23 15 04

  • Dart SDK version: 2.17.6 (stable)
  • Mac OS arm64
@lrhn
Copy link
Member

lrhn commented Sep 12, 2022

You're not showing us the original declaration of origin.
If the third example allows promotion to work, most likely the origin variable is a local variable declared as something like Provider<T, dynamic>, some type where FactoryProvider<T, dynamic> is a subtype, but FactoryProvider<dynamic, dynamic> (or the equivalent FactoryProvider) is not, because the dynamic type argument is not a subtype of T.

Dart promotion requires the new type to be a subtype of the current type, otherwise it wouldn't be promotion.

Now, it would be nice if we could infer type arguments for is FactoryProvider which allows promotion, but we currently don't.

@AlexanderFarkas
Copy link
Author

Great explanation. Thanks

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