-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add generic types to "new Collection.from" and "new Collection.unmodifiable" arguments #26383
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
Comments
One of the important use cases of Clearly, this would also be a big breaking change since a lot of the uses of |
Is this caused by #25220 ? That one wouldn't be all that hard to fix. But yeah, regardless it's useful to have some APIs that change the type (e.g. like C# Enumerable.Cast). |
In this case the best option would be to infer the type, if none was given, but allow to change it, when written explicitly. var list = new List.from(<num>[1, 2]); // => infer "List<num>".
var list2 = new List.from<int>(<num>[1, 2]); // => Use "int" but don't complain, that List<num> isn't a List<int>. If this was a very common use case, we would want this to be a language feature: // Use `other`'s generic type as inference if not given.
new List.from<T>(Iterable<??T> other) At the moment I don't think this will be warranted. |
I think this is a little misleading. The vast majority of calls to Casting is an operation that inherently runs a high risk of runtime failures. We shouldn't build it in to methods that have other purposes; we should require the user to be explicit about it. We can do this today using the
There's no equivalent to this for
This isn't clear to me. Do you have data about how many uses of
This is an API issue, not an inference issue. The constructors are typed as (for example) |
Oops, yeah, that makes sense |
This is done now. |
Right now,
new List.from()
and similar APIs take arguments with no generic types. This interferes with inference when using strong mode in two ways:new List.from()
is used, the user has to explicitly write the generic parameter since upwards inference can't work.Neither of these situations is particularly useful. As we go forth into a strong-mode-by-default world, these APIs should get updated.
The text was updated successfully, but these errors were encountered: