Skip to content

Support "fixing" switches with cascading conditions into switch expressions with || #52958

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
kevmoo opened this issue Jul 17, 2023 · 4 comments
Labels
devexp-quick-fix Issues with analysis server (quick) fixes legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@kevmoo
Copy link
Member

kevmoo commented Jul 17, 2023

I think I'm using the terms correctly.

  int get elementSize {
    switch (type) {
      case 'float':
      case 'int':
        return 4;
      case 'short':
        return 2;
      case 'byte':
        return 1;
      default:
        return 0;
    }

should have a suggested fix to

    return switch (type) {
      'float' || 'int' => 4,
      'short' => 2,
      'byte' => 1,
      _ => 0
    };

but it does not!

@kevmoo kevmoo added devexp-quick-fix Issues with analysis server (quick) fixes type-enhancement A request for a change that isn't a bug labels Jul 17, 2023
@pq
Copy link
Member

pq commented Jul 17, 2023

Yeah. We don't currently have the smarts to handle:

case 'float':
case 'int':
  return 4;

(but we should add 'em!)

@pq pq added the P3 A lower priority bug or feature request label Jul 17, 2023
@a-siva a-siva added the legacy-area-analyzer Use area-devexp instead. label Jul 18, 2023
@parlough
Copy link
Member

parlough commented Nov 16, 2023

An interesting workaround here is that you can convert to an if-case statement chain, then back to a switch statement, then finally to a switch expression :P

@FMorschel
Copy link
Contributor

FMorschel commented Aug 30, 2024

I believe this specific ask was already solved by #54567 (@srawlins to close this). I also created my request to it #55861 missing both.

Current related issues that I know of (1 request to separate the assist to merge the cases and 2 bugs with the current assist respectively):

There are also some other issues I created related to the formatter and some suggested lints all linked to the above issues.

@srawlins
Copy link
Member

srawlins commented Oct 1, 2024

Ah excellent, closing then.

@srawlins srawlins closed this as completed Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-quick-fix Issues with analysis server (quick) fixes legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants