Skip to content

Private interface method flagged as not referenced #60697

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
dowski opened this issue May 9, 2025 · 3 comments
Closed

Private interface method flagged as not referenced #60697

dowski opened this issue May 9, 2025 · 3 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request

Comments

@dowski
Copy link

dowski commented May 9, 2025

Problem

In Dart 3.7.2, when I declare a private interface method that I implement in some other classes, the Dart analyzer complains that it isn't referenced.

The declaration `_foo` isn't referenced.

Repro

Here's a DartPad that demonstrates the issue. I'll also paste the code here for clarity.

void main() {
  Bar().bar();
}

final class Bar {
  final foo = Foo();
  
  void bar() {
    foo._foo();
  }
}

final class Foo implements _Foo {
  @override
  void _foo() {}
}

abstract interface class _Foo {
  void _foo();
}

Additional Info

When using VS Code, it seems like the analyzer knows that _foo is used elsewhere because I can jump to implementors and callers. I assume that's powered by the analyzer too, so it's odd that this error is present.

@dowski dowski added the area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. label May 9, 2025
@FMorschel
Copy link
Contributor

Also #54374

CC @srawlins @eernstg

@srawlins
Copy link
Member

I believe it is flagged because it is unused as a method on _Foo. There is no reason for it to be in the interface contract of _Foo. It can just be declared on Foo.

@srawlins srawlins added devexp-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request labels May 12, 2025
@dowski
Copy link
Author

dowski commented May 13, 2025

Ah you're right! If I update the Bar class to use the interface _Foo, then the warning goes away.

final class Bar {
  // No more warning on _Foo._foo now.
  final _Foo foo = Foo();
  
  void bar() {
    foo._foo();
  }
}

I'll close this out - thanks!

@dowski dowski closed this as completed May 13, 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-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants