-
Notifications
You must be signed in to change notification settings - Fork 1.7k
language/covariant/subtyping_with_mixin_test is failing #41371
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Is this test valid, in class A {}
class B extends A {}
class Mixin<T> {
void f(T arg) {}
}
abstract class Interface {
void f(covariant A arg);
}
class C with Mixin<B> implements Interface {} We report The argument The fact that we later have a class @eernstg Where am I wrong here? |
@scheglov, I agree with the analysis. We had some very long discussions about this topic area, concluding here that it is an error if a concrete class class C {
void f(int x) {}
}
abstract class I {
void f(covariant num x);
}
class D extends C implements I {} // Error. I don't see a need to change this argument in order to work with null-safety. So your example here should mark I can see that 'tests/language/covariant/subtyping_with_mixin_test.dart' was added in CL @munificent, you migrated that test, do you have additional comments? I didn't notice this problem when I reviewed the CL, and I guess I relied on the version in 'language' to have sorted out that kind of problem already. ;-) But the conclusion I see here is that (1) any issues about changing the analyzer to accept these tests should be closed, and (2) if there is no issue about changing the tests to expect a compile-time error then such an issue should be created. @scheglov, does that match your view on the matter? |
@eernstg Yes, looks good to me, thank you. Should we also report the class C {
void f(int x) {}
}
abstract class I {
void f(covariant int x);
}
class D extends C implements I {} // Error. Currently analyzer does not report error for this example. |
None, if I recall right, I saw that the test was failing under language_2/ so I considered a failure in language/ to be a "correct" migration since it meant the test was doing the same thing as the unmigrated test. My goal isn't necessarily to fix all the bugs in the tests, so to have a migrated NNBD corpus of tests at parity with the legacy test. Sometimes parity means inadvertent bug-for-bug compatibility. I can't always tell what's a bug in the test or the implementation so I assume that if it does the same thing as the legacy test, at least I haven't made the test worse. :) |
@eernstg There seems to be a contradiction between reporting an error for implementation / interface covariant-be-declaration mismatch, and the other issue with a very similar code. In this other issue the conclusion was that "the analyzer should stop emitting an error". I'm confused. I was looking at a failing test |
@scheglov, sorry about the delay, I'm catching up after the Easter days. ;) There was the question about this example: class C {
void f(int x) {}
}
abstract class I {
void f(covariant int x);
}
class D extends C implements I {} // Error.
The underlying issue is that a concrete declaration (like In particular, void main() {
Function f = D().f;
void Function(Object) g = f; // Succeeds at run time.
g(Object()); // Statically checked call, no check on argument at call site.
} So even though there is no difference between the type annotation for So we can't just inherit We decided to make it an error when the reason for the dynamic check is that a parameter is covariant-by-declaration in the interface of the inheritor ( So class C1 {
void f(int x) {}
}
abstract class I1<X> {
void f(X x);
}
class D1 extends C1 implements I1<int> {} // OK. With The other issue was
for the following example: class A {}
class B extends A {}
class Base {
void f(B arg) {}
}
abstract class Interface {
void f(covariant A arg);
}
class C extends Base implements Interface {} That is inconsistent, and we should get the error: The following comment supports the claim that the language team decided to allow the implicitly induced forwarding stub for a parameter which is covariant-by-class, but not when it is covariant-by-declaration: #31580 (comment). So that particular reference ('here') is out of sync with the comment ('the analyzer should stop emitting an error'). Sorry about that; I added an extra sentence there to make it explicit that it is an error. This rule about inheritance is not specified in the language specification. I created dart-lang/language#925 to put that on the todo list. |
@scheglov, the language was changed in dart-lang/language#925, with implementation issue #47072, such that there should no more be an error for the situation where a class The behavior for that case today should be to make sure that the required dynamic check on the type of the actual argument passed to This might imply that https://dart-review.googlesource.com/c/sdk/+/146120 should be abandoned. Do you agree? |
SGTM |
No description provided.
The text was updated successfully, but these errors were encountered: