-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Redirecting factory constructors don't propagate generic type arguments #30855
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
The current specification requires (and allows!) you to write the type parameter of the target class. class C<T> {
C(T x) = GenericClass<T, Null>;
}
class GenericClass<T, S> implements C<T>, D<S> { ... } So, no automatic propagation, and the current behavior is Dart 1-correct, but you might want to infer the type parameter for the target class. That sounds reasonable (the target constructor must create a |
Sounds right to me. |
New front end does the right thing, so analyzer is more restrictive which makes this less of a priority. |
@leafpetersen When you say "propagate unchanged", do you mean only the case of redirecting to a constructor of the same class? class A<T, U> {
A();
factory A.redirected() = A;
} So, as I understand, all we need to do here is to replace Is there anything that can be (or should be) done for redirecting from an interface to the implementation? So, is there a way to know that class B<T, U> implements C<T, U> {}
class C<T1, U1> {
factory C() = B;
} |
This shouldn't be special - effectively the redirecting factory constructor: class A<T1, T2> {
factory A.foo(parameters) = B;
} is equivalent to: class A<T1, T2> {
factory A.foo(parameters) => new B(parameters);
} If |
OK, thanks. What happens when there are no parameters? So, in this example we still get a warning, because class A<T, U> {
A();
factory A.redirected() = A;
} |
The parameters shouldn't actually make much difference, I just had them there for completeness. I would expect that to infer: factory A.redirected() = A<T, U>; since the constructor needs to create an factory A.redirected() => new A(); // inferred: new A<T, U>(); |
[email protected] Bug: #30855 Change-Id: I05e9102fe7b7a304be6ac6dd4d59e11bdafee59c Reviewed-on: https://dart-review.googlesource.com/46575 Reviewed-by: Brian Wilkerson <[email protected]>
This code:
produces this error in current strong mode analyzer:
I believe that redirecting factory constructors should propagate their type arguments unchanged.
cc @bkonyi @jmesserly @lrhn @eernstg @floitschG @munificent @stereotype441
The text was updated successfully, but these errors were encountered: