Skip to content

Incorrect dead code removal quick fix when multiple cases share a body #56485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stereotype441 opened this issue Aug 15, 2024 · 1 comment
Closed
Assignees
Labels
legacy-area-analyzer Use area-devexp instead.

Comments

@stereotype441
Copy link
Member

The following code triggers the unreachable_switch_case hint:

enum E { e1, e2 }

_f(E e) {
  switch (e) {
    case E.e1:
    case E.e2:
    case E.e1: // hint shown here
      print('hello');
  }
}

That's behaving as expected. However, if I go to the location where the hint is reported, and invoke the "remove dead code" quick fix, the code is changed to:

enum E { e1, e2 }

_f(E e) {
  switch (e) {
    case E.e1:
    case E.e2:
  }
}

Which is not equivalent. The print('hello'); line shouldn't have been deleted, because it is not dead; only the extraneous case E.e1 is dead.

@stereotype441 stereotype441 added the legacy-area-analyzer Use area-devexp instead. label Aug 15, 2024
@stereotype441
Copy link
Member Author

I'm going to work on this, since otherwise it will block my ability to roll out a fix to #54575.

@stereotype441 stereotype441 self-assigned this Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead.
Projects
None yet
Development

No branches or pull requests

1 participant