Skip to content

[analysis_server] Extract method should not extract expressions in a constant context. #61146

@kallentu

Description

@kallentu

Currently, we allow extracting an expression when it's in a constant context, but that creates code that doesn't run (since we don't support constant functions).

For example:

enum E {
  v;
  void foo() {
    const e = E.v; // We extract E.v into a method using the extract method refactor
  }
}

Applies the refactoring to produce:

enum E {
  v;
  void foo() {
    const e = res(); // ERROR
  }

  E res() => E.v;
}

We should disallow the refactoring if we find that the expression is in a const context.

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-refactoringIssues with analysis server refactoringstype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions