Skip to content

[analyzer] Spurious unused_element #54543

@eernstg

Description

@eernstg

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.

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestdevexp-warningIssues with the analyzer's Warning codesimprove-diagnosticsRelated to the quality of diagnostic messageslegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions