Skip to content

[analyzer] prefer_final_locals incorrectly handles join pattern variables #61673

@incendial

Description

@incendial

Hi,

void fn(Object val) {
  if (val case SomeClass(:var value) || SomeClass(:var value)) { // <-- incorrectly suggests to use final
    value = 'str';
  }
}

void anotherFn() {
  var val = 1; // <-- works correctly, does NOT suggest final
  val = 3;
}

class SomeClass {
  final String value;

  const SomeClass(this.value);
}
Image

Dart SDK version: 3.8.1 (stable) (Wed May 28 00:47:25 2025 -0700) on "macos_arm64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.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