-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Type equality inconsistency for generic functions. #37484
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
Note the overlap with #32782 / #32783, which is associated with the test |
@lrhn is this a language bug to clarify the spec? |
The spec was updated in #34447 to say that For the bounds of type parameters of generic function types, the spec relies on renaming (generic function types are explicitly considered to be the same type if they only differ by choice of names), and this is not sufficient to establish a subtype relationship like This would also be a non-breaking change, according to the following test (which has no errors with the analyzer, also with main() {
void Function<X extends Object>(X) Function() f1 = null;
void Function<X extends Object>(X) Function() f2;
void Function<X extends dynamic>(X) Function() f3;
void Function<X extends D>(X) Function() f4pre<D>() => null;
var f4 = f4pre<dynamic>();
f2 = f1; f1 = f2; f3 = f2; f2 = f3; f3 = f4; f4 = f3;
f3 = f1; f1 = f3; f4 = f2; f2 = f4; f4 = f1; f1 = f4;
void Function<X extends List<dynamic>>(X) f6;
void Function<X extends List<FutureOr<void>>>(X) f7;
f6 = f7; f7 = f6;
} So I believe we can extract a spec change issue here: Change the subtype rules to use mutual subtyping for generic function type bounds—if we want to do that. If we don't want to change the subtype rules then Other than that, there is still the issue with the VM. |
Even if we change the specifiction to be " So, this is a VM bug. |
PS: Unless we change the subtype rules, it is also a dart2js bug. |
When we generate a
Type
object for a generic function, dart2js normalizesdynamic
bounds to be the same asObject
bounds, and the VM doesn't even consider structurally equal types to be equalType
objects.Example:
The VM is definitely wrong about equality of the structurally same type.
As to considering
dynamic
andObject
as the same bound, I guess that's reasonable, even though a little inconsistent (a bound ofvoid
is not equal).The text was updated successfully, but these errors were encountered: