Skip to content

No warnings in extension declarations, when there are member name collisions #41878

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
jwren opened this issue May 12, 2020 · 3 comments
Closed
Assignees
Labels
devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jwren
Copy link
Member

jwren commented May 12, 2020

See this code:

extension FileSystemEntityExtension on FileSystemEntity {
// method name collision with the path field:
String path() {
return '';
}

// name collision with the method:
bool get existsSync => false;
}

What's also confusing here is that the analyzer navigation and completion ignores them:

f(FileSystemEntity entity) {
  entity.path; //  <-- completes and navigates to lib/io/file_system_entity.dart
  entity.existsSync(); // <-- here too
}

@bwilkerson @scheglov

@jwren jwren added devexp-server Issues related to some aspect of the analysis server type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 12, 2020
@bwilkerson
Copy link
Member

I think this is WAI.

When resolving a member m against a type T, we first look in the type T and its supertypes for a definition of m. If one is found, we stop. If no member with that name is found, then we look for an extension. So the fact that it's resolving to the members in the class is correct.

The reason there's no diagnostic when colliding is (IIRC) because those members are still accessible via an extension override such as FileSystemEntityExtension(entity).path.

@scheglov
Copy link
Contributor

Yes, I agree that this WAI.

But as Brian mentioned in a CL, we might want to produce a hint on declared extension members if the extended type already declares a member with the same name.

@srawlins
Copy link
Member

srawlins commented Jun 7, 2020

I've requested this lint at #58182. I think this can be closed.

@scheglov scheglov closed this as completed Jun 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants