Skip to content

fix: quickfix deletes active functionality when removing unused variable #60663

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

Open
GuilhermeConstantino opened this issue May 2, 2025 · 1 comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-quick-fix Issues with analysis server (quick) fixes P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@GuilhermeConstantino
Copy link

Description
This was an issue that I opened in a library very_good_analysis, they sugested I opened it here.
Linter will remove function calls when made to a unused variable, even though the function itself might still be needed.

System used:
Windows.

Steps To Reproduce
Create a variable that receives the result of a function but is unused
Accept the quickfix
Expected Behavior
Future _postSomething(var something) {
final result = sendPostRequest(something);
}
Now since I didn't do anything with the result, it will cause a unused_local_variable linter
And when I select the "Remove unused local variable" quickfix it will delete the whole send, not just the variable.

Wanted result:
Future _postSomething(var something) {
sendPostRequest(something);
}

Actual result:
Future _postSomething(var something) {
}

Additional Context
The linter deleted some of my app functionality instead of just the variable.

@bwilkerson bwilkerson added devexp-quick-fix Issues with analysis server (quick) fixes area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels May 2, 2025
@FMorschel
Copy link
Contributor

Hey @GuilhermeConstantino, could you please confirm the Dart version you're using?

I just tested on the latest main with the following code, and everything works as you asked, only the code before foo(1); gets removed:

int foo(int p) => 0;
void f(str) {
  final removed = foo(1);
}

We have a similar test case here (but for methods) that was added more than a year ago:

Future<void> test_assigned_inDeclaration() async {
await resolveTestCode(r'''
List<String> l = [];
void f(str) {
final removed = l.remove(str);
}
''');
await assertHasFix(r'''
List<String> l = [];
void f(str) {
l.remove(str);
}
''');
}

I still opened https://dart-review.googlesource.com/c/sdk/+/426380 to add a test for functions specifically.

If you can give more information, it would be great! If you want to test on the latest stable Dart and don't have it installed, you can test in https://dartpad.dev/ with no need to install anything else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-quick-fix Issues with analysis server (quick) fixes P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants