Skip to content

Invalid rename from Inline Method #60634

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
bwilkerson opened this issue Apr 28, 2025 · 0 comments
Open

Invalid rename from Inline Method #60634

bwilkerson opened this issue Apr 28, 2025 · 0 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-assist Issues with analysis server assists 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

@bwilkerson
Copy link
Member

Given a file containing the following:

Future<void> f(ChangeBuilder builder) async {
  var changeBuilder = builder as ChangeBuilderImpl;
  int computeChangeHash() => changeBuilder.changeHash;

  computeChangeHash();
}

class ChangeBuilder {}

class ChangeBuilderImpl implements ChangeBuilder {
  int get changeHash => 0;
}

Select the name of the local function computeChangeHash and invoke the "Inline Method" assist. The result will be

Future<void> f(ChangeBuilder builder) async {
  var changeBuilder = builder as ChangeBuilderImpl;

  changeBuilder2.changeHash;
}

class ChangeBuilder {}

class ChangeBuilderImpl implements ChangeBuilder {
  int get changeHash => 0;
}

The reference to the local variable changeBuilder is erroneously changed to changeBuilder2.

I suspect that this is because the assist doesn't know that the "method" being inlined is a local function and that local variables from outside the function are still valid to reference.

We probably need an "Inline Local Function" variant that knows what's being inlined. It will still need to be aware of the possibility of shadowing.

@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-assist Issues with analysis server assists 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 Apr 28, 2025
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-assist Issues with analysis server assists 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

1 participant