Skip to content

"Create method" quick fix doesn't understand about named-arguments-anywhere. #62878

@stereotype441

Description

@stereotype441

This code:

class C {}

f(C c) {
  c.m(arg1: true, 0, arg3: 'string'); // (1)
}

has a compile-time error at (1): "The method 'm' isn't defined for the type 'C'."

Note that the call site has a named argument followed by a positional argument followed by a named argument. This has been allowed since 2.17 (it's the "named-argument-anywhere" feature).

There's a quick fix available: "Create method 'm'." But triggering it gives incorrect results:

class C {
  void m({required bool arg1, int i, required String arg3}) {}
}

f(C c) {
  c.m(arg1: true, 0, arg3: 'string');
}

Note that in the generated method, i is a named argument; it should be a positional argument, i.e.:

class C {
  void m(int i, {required bool arg1, required String arg3}) {}
}

f(C c) {
  c.m(arg1: true, 0, arg3: 'string');
}

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-quick-fixIssues with analysis server (quick) fixestype-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