Skip to content

prefer_final_locals incompatible with record destructuring in for loops #59120

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

Closed
TzviPM opened this issue Apr 21, 2023 · 2 comments
Closed

prefer_final_locals incompatible with record destructuring in for loops #59120

TzviPM opened this issue Apr 21, 2023 · 2 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead.

Comments

@TzviPM
Copy link
Contributor

TzviPM commented Apr 21, 2023

Describe the issue

prefer_final_locals fails when destructuring a record in a for loop. See below for a simple example

To Reproduce

Dart code in records.dart:

final people = [
  ("John", 20),
  ("Jane", 21),
  ("Jack", 22),
];

void main(List<String> args) {
  for (final (name, age) in people) {
    print("$name is $age years old");
  }
}

run with dart --enable-experiment=records records.dart

Output:

John is 20 years old
Jane is 21 years old
Jack is 22 years old
$ dart --version
Dart SDK version: 3.1.0-15.0.dev (dev) (Tue Apr 18 07:11:59 2023 -0700) on "macos_arm64"

In analysis_options.yaml:

linter:
  rules:
    - prefer_final_locals

then analysis fails:

$ dart analyze
Analyzing dart_rec...                  0.7s

   info • records.dart:8:15 • Local variables should be final. Try
          making the variable final. • prefer_final_locals
   info • records.dart:8:21 • Local variables should be final. Try
          making the variable final. • prefer_final_locals

2 issues found.

Expected behavior

prefer_final_locals should recognize that the destructured locals are final.

Additional context

None

@TzviPM
Copy link
Contributor Author

TzviPM commented Apr 21, 2023

See also: #59117

@TzviPM
Copy link
Contributor Author

TzviPM commented Apr 21, 2023

Looks like this was fixed already via dart-archive/linter#4287

@TzviPM TzviPM closed this as completed Apr 21, 2023
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead.
Projects
None yet
Development

No branches or pull requests

2 participants