Closed as not planned
Description
When redirecting non-generic class to generic implementation you always lose generic argument.
Example:
sealed class Size {
const Size();
const factory Size.static(int size) = StaticSize;
/// possible
const factory Size.dynamic(ValueElement element) = DynamicSize;
/// desired
const factory Size.dynamic2<T extends ValueElement>(T element) = DynamicSize<T>;
/// possible as method, but it's not a constructor and __not const__
static Size dynamic3<T extends ValueElement>(T element) => DynamicSize<T>(element);
int get size;
}
final class StaticSize implements Size {
const StaticSize(this.size);
@override
final int size;
}
final class DynamicSize<T extends ValueElement> implements Size {
const DynamicSize(this.element);
final T element;
@override
int get size => element.asInt;
}
About instantiation, you can't call constructor like const Size<T>.dynamic(value)
because Size
have no argument and that's ok, but you can do const Size.dynamic<T>(value)
if it's static method, but not a constructor.
It would be nice to have an exception for redirecting constructors to have generics, because that would allow better usage of const factory
.