Skip to content

Report lint when an extension member name collides with extendee member name #58182

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

Open
srawlins opened this issue Jun 7, 2020 · 0 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-lint-request P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@srawlins
Copy link
Member

srawlins commented Jun 7, 2020

Describe the rule you'd like to see implemented

See #41878 and dart-lang/language#966.

Extensions are legally allowed to declare members whose names collide with members declared on the extended class. However, this is often undesirable. A) it is difficult to call the extension member; it can only be called by explicitly using the extension's name. B) it may be accidental; it may be that in some versions of the extended class, there is no collision, and in later versions, there is. If a developer is editing an extension with a member which newly collides with another member, it would be good to know.

Extensions mean that adding a member to a class may be a breaking change for the new reason that code which previously called an extension member would now call this mysterious new member.

Examples

// package_one/a.dart in version 1.0
class C {}
// package_one/a.dart in version 2.0
class C {
  foo() => "x";
}
// package_two/b.dart
extension E on C {
  foo() => "y";
}

Libraries which import package_two/b.dart will get different behavior based on which package pub has fetched for their code's .packages file. Without any static analysis warnings, the author of package_two/b.dart does not know that their extension member overrides an existing member, when they upgrade their dependency on package_one to include 2.0.

@srawlins srawlins added type-enhancement A request for a change that isn't a bug linter-lint-request labels Jun 7, 2020
@srawlins srawlins added the P3 A lower priority bug or feature request label Oct 17, 2022
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-lint-request P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants