Skip to content

Bogus unnecessary_this with pattern matching and shadowing #59152

Closed
dart-archive/linter
#4542
@nex3

Description

@nex3

For the code below:

class Foo {
  Object? value;

  bool equals(Object other) => switch (other) {
    Foo(: var value) => this.value == value,
    _ => false
  };
}

the 3.0.0 analyzer will print

info - test.dart:5:25 - Unnecessary 'this.' qualifier. Try removing 'this.'. - unnecessary_this

This is incorrect. The this. is necessary to disambiguate the containing class's value field from the value variable bound by the switch expression.

Metadata

Metadata

Assignees

Labels

P1A high priority bug; for example, a single project is unusable or has many test failuresdevexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.linter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.linter-set-recommendedtype-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