-
Notifications
You must be signed in to change notification settings - Fork 28
Add Subtyping tests for function types with covariant-by-declaration parameters #2087
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
Ah, I'm afraid I don't understand what that would be. A function type that contains Tear-offs of those instance methods do have a function type, but it doesn't contain Could you clarify this a bit? |
Ah, we strip class A {
void foo(num n) {
print("A");
}
}
class C implements A {
void foo(covariant int n) {
print("C");
}
}
main() {
C c = C();
void Function(num n) f = c.foo; // Error. `covariant` doesn't allow us to override function type restrictions
}
|
When I was filling this issue I supposed an opposite test. That tear-off of |
Yes, that's a compile-time error because the member class A {
void foo(num n) => print("A");
}
class C implements A {
void foo(covariant int n) => print("C");
}
main() {
A a = C();
void Function(num n) f = a.foo; // OK at compile time; succeeds at run time, too.
f(1.5); // But this throws.
} The unusual bit here is that the static type of the tear-off is different from the dynamic type of the tear-off, even in the case where the static type of the receiver is exactly the run-time type of the receiver as well. The reason for this is that it is safer to assign the tear-off to a variable whose type won't cause the built-in argument type check to throw. In other words, we can assign In some cases we don't know the exact type of the receiver and in that case we can't see the potential dynamic error at compile time (as in |
…h covariant arguments
Add tests for parameters covariant-by-declaration
2023-07-14 [email protected] Fixes dart-lang/co19#2132. Fix roll failures, add issue numbers (dart-lang/co19#2134) 2023-07-13 [email protected] Fixes dart-lang/co19#2130. Fix roll failures, add issues numbers (dart-lang/co19#2131) 2023-07-13 [email protected] Fixes dart-lang/co19#2125. Add more external functions tests (dart-lang/co19#2128) 2023-07-13 [email protected] Fixes dart-lang/co19#2087. Reorder covariance tests to make maintenance easier (dart-lang/co19#2129) 2023-07-12 [email protected] dart-lang/co19#2087. Add tests for parameters covariant-by-declaration (dart-lang/co19#2121) 2023-07-12 [email protected] Fixes dart-lang/co19#2117. Update assertions, add tests for external members (dart-lang/co19#2126) 2023-07-12 [email protected] Fixes dart-lang/co19#2123. Update Superclasses tests. (dart-lang/co19#2124) 2023-07-11 [email protected] dart-lang/co19#2117. Update accessible_instance_member_t* tests (dart-lang/co19#2122) 2023-07-10 [email protected] Fixes dart-lang/co19#2099. Add subtyping tests for function type with required named arguments (dart-lang/co19#2100) 2023-07-10 [email protected] dart-lang/co19#2112. Add missing tests for mixins. Part 2 (dart-lang/co19#2118) 2023-07-07 [email protected] dart-lang/co19#2119. Minor wording changes (dart-lang/co19#2120) Change-Id: I310f2e0a660ac55a242bb9b2ed9a2f1917555d0f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313562 Reviewed-by: Alexander Thomas <[email protected]>
2023-07-14 [email protected] Fixes dart-lang/co19#2132. Fix roll failures, add issue numbers (dart-lang/co19#2134) 2023-07-13 [email protected] Fixes dart-lang/co19#2130. Fix roll failures, add issues numbers (dart-lang/co19#2131) 2023-07-13 [email protected] Fixes dart-lang/co19#2125. Add more external functions tests (dart-lang/co19#2128) 2023-07-13 [email protected] Fixes dart-lang/co19#2087. Reorder covariance tests to make maintenance easier (dart-lang/co19#2129) 2023-07-12 [email protected] dart-lang/co19#2087. Add tests for parameters covariant-by-declaration (dart-lang/co19#2121) 2023-07-12 [email protected] Fixes dart-lang/co19#2117. Update assertions, add tests for external members (dart-lang/co19#2126) 2023-07-12 [email protected] Fixes dart-lang/co19#2123. Update Superclasses tests. (dart-lang/co19#2124) 2023-07-11 [email protected] dart-lang/co19#2117. Update accessible_instance_member_t* tests (dart-lang/co19#2122) 2023-07-10 [email protected] Fixes dart-lang/co19#2099. Add subtyping tests for function type with required named arguments (dart-lang/co19#2100) 2023-07-10 [email protected] dart-lang/co19#2112. Add missing tests for mixins. Part 2 (dart-lang/co19#2118) 2023-07-07 [email protected] dart-lang/co19#2119. Minor wording changes (dart-lang/co19#2120) Change-Id: I310f2e0a660ac55a242bb9b2ed9a2f1917555d0f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/313562 Reviewed-by: Alexander Thomas <[email protected]>
Add Subtyping tests for function types with covariant-by-declaration parameters
The text was updated successfully, but these errors were encountered: