-
Notifications
You must be signed in to change notification settings - Fork 53
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
ListBuilder.replace(Iterable iterable) accepts dynamic Iterable #190
Comments
Yes; it allows you to 'cast' an This made more sense in Dart 1 than Dart 2. In Dart 1, this:
has type But it would be an incompatible change now, so we're stuck with it even thought |
If someone is using this method with incompatible type iterables then they are getting run time exceptions. My guess that there shouldn't be a lot of usage in real world? Anyway problem is that my code is error prone because of this unchecked method. We had scenario where we changed code to incompatible types with expectation that compiler will show problems, but everything blew at runtime. This is very oversimplified example, we change class Producer {
Iterable<Item> retrieveItems() {...}
MySafeState getState() {
return state.update((b) => items.replace(retrieveItems()));
}
} Whole purpose we use Wouldn't it be reasonable to release new major |
The problem is that it's currently like a cast: you can pass in an Changing it would require changing every caller that's using it as a cast instead of an assignment. (We could add a I tried making the change to see what broke--at the very least, It definitely makes sense to do this if/when we release a breaking change to Thanks for filing, though. Its good to have more attention on this issue :) |
This would be appreciated 🏅 Still will need to manually check in PRs that noone is using |
It's the other way around, I'm afraid; So we could add |
For people using I would welcome either a breaking change or a second replaceXXX() method with type parameters, too. |
What if we changed it to take |
Should get rid of the manually specified type and work, given to covariant nature of generics in Dart, and should also be a non-breaking change. Drawback:
would still compile. |
Right.
|
Closing in favour of #241 |
Is this intentional to pass
Iterable<dynamic> iterable
or it could be reused genericE
here like?The text was updated successfully, but these errors were encountered: