Skip to content

Convert to switch expression removes when #60966

Open
@gabrielgarciagava

Description

@gabrielgarciagava

When using the "convert to switch expression", the "when" parts are removed, which is very error prone (if you have a default case, you may miss it is gone)

Example:

int foo(int a, bool x) {
  switch (a) {
    case 1 when x:
      return 1;
    default:
      return 3;
  }
}

becomes

int foo(int a, bool x) {
  return switch (a) {
    1 => 1,
    _ => 3
  };
}

Tested with both Dart 3.8.1 (flutter stable) and 3.9.0-241.0.dev

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions