Skip to content

[cfe] Error reported for spurious conflict involving static and extension method #48834

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
eernstg opened this issue Apr 19, 2022 · 2 comments
Closed
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@eernstg
Copy link
Member

eernstg commented Apr 19, 2022

Thanks to @athomas for raising this issue. Consider the following program:

extension HashAll on Iterable {
  int hashAll() => 0;
}

extension HashAllList on List {
  int hashAll() => 1;
}

void main() {
  List l = [];
  Iterable i = [];
  print(l.hashAll());
  print(i.hashAll());
}

The CFE (using dart from commit 20b5602) reports a conflict with a static member of the class Object:

n008.dart:2:7: Error: This extension member conflicts with Object member 'hashAll'.
  int hashAll() {
      ^^^^^^^
n008.dart:8:7: Error: This extension member conflicts with Object member 'hashAll'.
  int hashAll() {
      ^^^^^^^

However, I cannot find a justification in the specification documents that any such conflict should be reported. Intuitively, it would not be a conflict anyway, because access to the static method hashAll in Object would have to use the syntax Object.hashAll or prefix.Object.hashAll everywhere outside the class Object itself, and those forms cannot be an access to the extension methods shown above (assuming that Object resolves to the built-in class and hasn't been shadowed by declaration like a local variable).

I believe the conflict should not be reported. The behavior is CFE specific, the analyzer doesn't report a conflict.

@eernstg eernstg added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) legacy-area-front-end Legacy: Use area-dart-model instead. labels Apr 19, 2022
@eernstg
Copy link
Member Author

eernstg commented Apr 19, 2022

Actually, the spec needs to be clarified here:

$D$ declares a member (static or not) with the same basename as a
member declared by the built-in class \code{Object}.

It should be adjusted to say 'an instance member'. Cf. dart-lang/language#2207.

@eernstg eernstg removed the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 19, 2022
@chloestefantsova
Copy link
Contributor

I'm working on a fix at https://dart-review.googlesource.com/c/sdk/+/241603.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

2 participants