Skip to content

[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

Closed
Tracked by #49732
eernstg opened this issue Oct 10, 2023 · 9 comments
Assignees
Labels
dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec feature-extension-types Implementation of the extension type feature legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on

Comments

@eernstg
Copy link
Member

eernstg commented Oct 10, 2023

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:

extension type E1(int i) {
  set m(_) {}
}

extension type E2(int i) implements E1 {
  void m() {}
}

void main() {
  E2(1).m = 10;
}

The analyzer reports the following error for the example, which is from #53717:

Class 'E2' can't define method 'm' and have field 'E1.m' with the same name.

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 than m, but presumably the analyzer error messages consider setters to have names like m in general, without the =.)

@bwilkerson
Copy link
Member

Yes, diagnostic messages do not include the = because users don't see the = anywhere in their code.

The rewrite lgtm.

@srawlins srawlins added feature-extension-types Implementation of the extension type feature P2 A bug or feature request we're likely to work on labels Oct 17, 2023
@scheglov
Copy link
Contributor

In the analyzer explicit getters and setters declare implicit fields.

@bwilkerson
Copy link
Member

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.

@eernstg
Copy link
Member Author

eernstg commented Nov 14, 2023

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.

@scheglov
Copy link
Contributor

@eernstg
Copy link
Member Author

eernstg commented Nov 24, 2023

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.)

@eernstg eernstg added dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec and removed improve-diagnostics Related to the quality of diagnostic messages labels Nov 24, 2023
@eernstg
Copy link
Member Author

eernstg commented Nov 24, 2023

@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 eernstg added implementation Track the implementation of a specific feature (use on area-meta issue, not issues for each tool) and removed implementation Track the implementation of a specific feature (use on area-meta issue, not issues for each tool) labels Nov 24, 2023
@eernstg eernstg changed the title [analyzer] [extension types] Method/setter clash diagnostic is confusing [analyzer] [extension types] Implement 'precludes' rule to eliminate method/setter conflicts Nov 24, 2023
@scheglov
Copy link
Contributor

scheglov commented Nov 27, 2023

@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(_) {}
}

@eernstg
Copy link
Member Author

eernstg commented Nov 28, 2023

That's a good question!

The current wording in the feature specification makes it an error to have implements E1, E2 on an extension type that doesn't declare a member named foo, and there's no help from having the setter foo= because that's not taken into account at that location in the spec.

However, the rule about 'precludes' clearly specifies that E3 has the getter named foo, and not the method.

This means that the original motivation for making the conflict in the superinterface an error on E3 is gone.

See dart-lang/language#3486.

copybara-service bot pushed a commit that referenced this issue Nov 28, 2023
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]>
@scheglov scheglov closed this as completed Dec 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec feature-extension-types Implementation of the extension type feature legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

4 participants