Open
Description
Summary:
I'm expecting to be able to narrow generics when using extensions. We are having to use extensions to properly identify a self return type of T1, but that needs to also come with the ability to narrow the generic within the Extension implementation.
I'm sure there is a valid reason why this is not occuring, but the allowed syntax (narrowing) and the implementation resulting from the syntax currently diverges. Either the syntax needs to be disallowed (which I hope is not the course of action) or the extension needs to correctly use the narrowed generic.
Version:
$dart --version
Dart SDK version: 2.18.5 (stable) (Tue Nov 22 15:47:29 2022 +0000) on "macos_arm64"
Reproduce:
main(){
final otherClass = OtherClass();
final test = TestClass();
test.method(otherClass); // !!! This should be an analyzer + runtime error
}
class OtherClass {}
class OtherClassChild extends OtherClass {}
mixin TestMixin<T extends OtherClass> {}
class TestClass with TestMixin<OtherClassChild>{}
extension TestMixinExtension<T1 extends TestMixin<T2>, T2 extends OtherClass> on T1 {
T1 method(final T2 should_be_narrowed_to_other_class_child){
return this;
}
}