-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Analyzer performs override check between superinterfaces and superclass #34392
Comments
@leafpetersen - did we do this on purpose? IIRC, strong mode initially did not allow abstract members to override concrete ones with a different signature. But that may have been for simplicity of the implementation. We could certainly relax this and accept this example. (Not sure if there's a Dart 2 spec for how this should work?) As I was thinking about this, it occurred to me that abstract member overrides could probably break soundness in Analyzer, and sure enough: class C {
Object foo() => 42;
}
abstract class D extends C {
String foo([int x]);
}
class E extends D {}
main() {
String s = E().foo(123); // OOPS!
print(s.trim());
} So we've got to fix something here regardless. If we fix how concrete classes are checked against their interfaces, both of these examples will behave correctly (accepting the initial example, rejecting my example above). |
I have filed the missing interface checks in the analyzer as #34507. |
The current language specification specifies overriding in such a way that we must update it; e.g., it makes
So we can't just take everything from the language specification and be done with it. However, the language specification does insist that the interface 'overrides' and 'inherits' relations treat all superinterfaces identically, so it would be a breaking change to start giving the superclass a different treatment than the classes that the current class Now, when we have several different member signatures for a given name and none is most specific, the language specification specifies that we will compute an interface whose type annotations are all So we discussed how to update the specification on this topic. The following feature spec is in the pipeline (though not yet landed): interface-conflicts.md, introduced by this CL. This feature spec specifies, exactly as stated by @askeksa-google, that all superinterfaces (i.e., the interface of the superclass as well as the interface of each class that it @leafpetersen, @lrhn, do you agree that there is no doubt about the symmetric treatment of all superinterfaces? Do you foresee any changes to said feature spec with respect to the treatment of conflicts? PS: The feature spec has a discussion about erasing certain top types to |
OK, given that the specification is not complete, I'm moving this out of |
There is no doubt that we want the symmetric approach where the most specific member declaration among all super-interfaces is the interface signature inherited by the subclass (when it doesn't declare a signature itself). That has been the intended behavior for Dart 2.0 all along. |
Actually, dartLangSpec.tex does specify an error, as of a07b2a1, whenever there is no most-specific signature for a given member |
This would be good to fix for 2.1. |
https://dart-review.googlesource.com/c/sdk/+/76061 (re)implements handling inheritance according to the updated spec, and how it was explained to me in mail. This fixes Analyzer for the original code, so it does not report any error. |
This CL starts moving checks from strong-mode specific checker, and old InheritanceManager into an implementation that is based on the current spec, and avoids old baggage. It also fixes the issue we were asked to fix for Dart 2.1. Bug: #34392 Change-Id: Id5a23c5db7704b2b530bb894ae92628a08eaa70f Reviewed-on: https://dart-review.googlesource.com/76061 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Bug: #34392 Change-Id: Ia86264e8e752d7563b97657321f92eaa53f257bb Reviewed-on: https://dart-review.googlesource.com/76180 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Relands https://dart-review.googlesource.com/c/sdk/+/76061 Was reverted in https://dart-review.googlesource.com/c/sdk/+/76301 The difference with the original CL is that we don't look into superclass and mixins of mixed-in for concrete members. This reduces the number of errors in Flutter codebase to 1. R=brianwilkerson@google.com Bug: #34392 Change-Id: I86256b598d116439194cbaf4d09b4f72013d6563 Reviewed-on: https://dart-review.googlesource.com/76340 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
The analyzer complains (at the declaration of
B
) that thefoo
method inA
is not a valid override of thefoo
method inI
.There is no override relationship between those two methods, so having them both in
B
is valid, because all of the following hold:This looks like it could be some mix-up between override checking and checking that every concrete class conforms to its interface.
The text was updated successfully, but these errors were encountered: