Skip to content
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

No quick fix for unused_local_variable when local variable defined in a pattern #52150

Closed
stereotype441 opened this issue Apr 24, 2023 · 2 comments
Assignees
Labels
analyzer-language-patterns Issues with analyzer's support for the patterns language feature analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on

Comments

@stereotype441
Copy link
Member

The following Dart 3.0 code has an unused_local_variable diagnostic for the unused variable k:

f(MapEntry e) {
  switch (e) {
    case MapEntry(key: [var a, var b] && var k, :var value):
      print('[$a, $b]: $value');
  }
}

It would be nice to have a quick fix that removes the redundant && var k, leaving:

f(MapEntry e) {
  switch (e) {
    case MapEntry(key: [var a, var b], :var value):
      print('[$a, $b]: $value');
  }
}

Similarly, in this code:

f(MapEntry e) {
  var MapEntry(:key, :value) = e;
  print('Key is $key');
}

It would be nice to have a quick fix that removes the redundant , :value, leaving:

f(MapEntry e) {
  var MapEntry(:key) = e;
  print('Key is $key');
}

And in this code:

f((String, int) r) {
  var (s, i) = r;
  print('$i');
}

It would be nice to have a quick fix that replaces the unused local variable s with a wildcard pattern, leaving:

f((String, int) r) {
  var (_, i) = r;
  print('$i');
}
@stereotype441 stereotype441 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-quick-fix analyzer-language-patterns Issues with analyzer's support for the patterns language feature labels Apr 24, 2023
@scheglov
Copy link
Contributor

Actually, with https://dart-review.googlesource.com/c/sdk/+/296761 we do support removing unused variable patterns from object and record patterns.
image
image
Removing from the logical-and pattern is not implemented yet.
I did not think about it, but now I see when it might be useful.

@scheglov scheglov added the P2 A bug or feature request we're likely to work on label Apr 24, 2023
@scheglov scheglov self-assigned this Apr 24, 2023
@scheglov
Copy link
Contributor

copybara-service bot pushed a commit that referenced this issue Apr 24, 2023
…erns.

Bug: #52150
Change-Id: I9efb2f8ece0ccb3d3c2e276ff708a671dea80fa3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/297841
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-language-patterns Issues with analyzer's support for the patterns language feature analyzer-quick-fix area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

2 participants