Skip to content

Constructor parameters of generic class are wrongly marked as unused #47839

Description

@srawlins

Take this simple example:

class C<T> {
  C._([int? x]);
}
void foo() {
  C._(7);
}

analyzer reports int? x as an UNUSED_ELEMENT, citing that "a value for optional parameter 'x' isn't ever given." :cringe:.

The issue is that analyzer looks at a constructor invocation like C._(7), for a generic class, and performs inference, and replaces each ParameterElement with a fresh, synthetic, ParameterElement. Then the "corresponding parameter element" for 7 (the synthetic thing) is marked as used, and meanwhile the real ParameterElement is never marked used.

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-warningIssues with the analyzer's Warning codestype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions