-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[analyzer] [extension types] Implement 'precludes' rule to eliminate method/setter conflicts #53719
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
Yes, diagnostic messages do not include the The rewrite lgtm. |
In the analyzer explicit getters and setters declare implicit fields. |
But in messages to users we should always refer to the explicit getter or setter. Referring to an implicit field is confusing because users don't think of there being an implicit field. |
Here's a proposal that allows methods and setters to shadow each other: dart-lang/language#3470. If the language team prefers to do this (and change the specification such that the example in the original posting isn't an error) then there will be a need to change the analyzer accordingly. Sorry about the twisted path that this topic is following. |
Just to clarify: The language team did support the proposal in dart-lang/language#3470, and https://dart-review.googlesource.com/c/sdk/+/337641 implements the new rules. (This means that this issue has been reinterpreted from "improve the diagnostic given when we have this kind of method/setter conflict" to "use the new rules based on the notion of 'precludes' to eliminate this kind of method/setter conflict". I've edited the original post in order to indicate this change.) |
@scheglov, I adjusted the labels based on the fact that the language has changed and this issue is associated with the implementation of the new rules. Please re-adjust the labels if there's a better way to do it. |
@eernstg is this valid code? Do we filter out precluded declarations first, or do we find the unique inherited declaration (report an error if is not unique) and see that it is precluded? FWIW, it is easier to check the unique setter/method to see if it is precluded by declared method/setter. extension type E1(int it) {
void foo() {}
}
extension type E2(int it) {
int get foo => 0;
}
extension type E3(int it) implements E1, E2 {
set foo(_) {}
} |
That's a good question! The current wording in the feature specification makes it an error to have However, the rule about 'precludes' clearly specifies that This means that the original motivation for making the conflict in the superinterface an error on |
See dart-lang/language#3470 Bug: #53719 Change-Id: Iab840870a4d5be18a591f8fcef81bacb4a5d22cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337641 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
Edit, Nov 24 2023: This issue has been retargeted, and it is no longer about improving the diagnostic message for a certain method/setter conflict. Instead, the language was modified such that those conflicts do not exist any more, and this issue is now the implementation issue for the new rules.
As such, this is now the analyzer specific issue for #53717.
This is the analyzer specific issue for #53717. Consider the following example:
The analyzer reports the following error for the example, which is from #53717:
This is confusing because there are no instance variable declarations named
m
anywhere in this program. It would probably be helpful to report something like "Class 'E2' can't define method 'm' and have a setter 'E1.m' with the same name".(The language specification documents would say that the name of the setter is
m=
rather thanm
, but presumably the analyzer error messages consider setters to have names likem
in general, without the=
.)The text was updated successfully, but these errors were encountered: