Skip to content
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

[analyzer] Spurious unused_element #54543

Closed
eernstg opened this issue Jan 8, 2024 · 2 comments
Closed

[analyzer] Spurious unused_element #54543

eernstg opened this issue Jan 8, 2024 · 2 comments
Assignees
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. improve-diagnostics Related to the quality of diagnostic messages P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented Jan 8, 2024

Consider the following library:

// Library 'n010lib.dart'.

typedef E<X> = _E<X>;

extension type _E<X>._(X x) {
  _E.named(X x) : this._(x);
}

This library gives rise to the following diagnostic when processed by the analyzer (6672353):

Analyzing n010lib.dart...              0.4s

   info • n010lib.dart:6:6 • The declaration '_E.named' isn't
          referenced. Try removing the declaration of '_E.named'. •
          unused_element

1 issue found.

However, it isn't true that _E.named is known to be unused. For example, we can use it from a library n010.dart with the following contents:

// Library 'n010.dart'.
import 'n010lib.dart';

void main() {
  E<int>.named(1);
}

The point is that _E should not be considered to be a private type when it has been made reachable via a type alias.

@eernstg eernstg added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. improve-diagnostics Related to the quality of diagnostic messages labels Jan 8, 2024
@bwilkerson
Copy link
Member

@srawlins

@srawlins
Copy link
Member

srawlins commented Jan 8, 2024

Well played!

@srawlins srawlins added P3 A lower priority bug or feature request analyzer-warning Issues with the analyzer's Warning codes labels Jan 8, 2024
kevmoo added a commit to ChreSyr/json_serializable.dart that referenced this issue Mar 2, 2024
kevmoo added a commit to ChreSyr/json_serializable.dart that referenced this issue Mar 2, 2024
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 5, 2024
@srawlins srawlins self-assigned this Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. improve-diagnostics Related to the quality of diagnostic messages P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants