Skip to content

Invalid rename from Inline Method #60634

Open
@bwilkerson

Description

@bwilkerson

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.

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-assistIssues with analysis server assiststype-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