Skip to content

Extract Method extracts to non-static method in static context #4564

@mosuem

Description

@mosuem

Describe the bug
Given a method

static String test = getNameBy((v) => v.toString());

when calling Extract Method on the inner lambda, it extracts to

static String test = getNameBy(newMethod);
String newMethod(v) => v.toString();

which then gives the implicit_this_reference_in_initializer error. It should instead extract to

static String test = getNameBy(newMethod);
static String newMethod(v) => v.toString();

Please complete the following information:
Dart SDK version: 3.1.0-39.0.dev (dev) (Mon Apr 24 18:53:55 2023 -0700) on "linux_x64"

Version: 1.78.0
Commit: 252e5463d60e63238250799aef7375787f68b4ee
Date: 2023-05-03T20:09:46.685Z
Electron: 22.4.8
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Linux x64 6.1.20-2rodete1-amd64
Sandboxed: No

Dart-Code v3.65.20230520 Pre-Release

Metadata

Metadata

Assignees

No one assigned

    Labels

    in editorRelates to code editing or language featuresin lsp/analysis serverSomething to be fixed in the Dart analysis serveris bugrelies on sdk changesSomething that requires changes in the Dart/Flutter SDK to ship before it will become available

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions