Skip to content

update CONVERT_TO_SWITCH_EXPRESSION to handle cases w/o breaks #51826

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
pq opened this issue Mar 22, 2023 · 3 comments
Closed

update CONVERT_TO_SWITCH_EXPRESSION to handle cases w/o breaks #51826

pq opened this issue Mar 22, 2023 · 3 comments
Labels
devexp-assist Issues with analysis server assists devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Milestone

Comments

@pq
Copy link
Member

pq commented Mar 22, 2023

Example:

enum E { e1, e2 }

f(E e) {
  var v;
  switch (e) {
    case E.e1:
      v = 'e1';
    case E.e2:
      v = 'e2';
  }
}

should convert to:

enum E { e1, e2 }

f(E e) {
  var v = switch (e) {
    E.e1 => 'e1',
    E.e2 => 'e2',
  };
}

/fyi @bwilkerson @johnpryan @MaryaBelanger

@pq pq added legacy-area-analyzer Use area-devexp instead. devexp-server Issues related to some aspect of the analysis server P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug devexp-assist Issues with analysis server assists labels Mar 22, 2023
@pq pq added this to the Dart 3 beta 3 milestone Mar 22, 2023
@bernaferrari
Copy link
Contributor

bernaferrari commented Mar 23, 2023

Hey, does your thing work with this?

switch (textDirection) {
  case TextDirection.rtl:
    borderRadius = indicatorBorderRadius.copyWith(topRight: Radius.zero, bottomRight: Radius.zero);
  case TextDirection.ltr:
    borderRadius = indicatorBorderRadius.copyWith(topLeft: Radius.zero, bottomLeft: Radius.zero);
}

The borderRadius declaration is far away, I still wish the end result were borderRadius = switch(...).

@pq
Copy link
Member Author

pq commented Mar 23, 2023

Hey @bernaferrari! That should work just fine. When this lands, you should get an assist that produces:

borderRadius = switch (textDirection) {
  TextDirection.rtl => indicatorBorderRadius.copyWith(topRight: Radius.zero, bottomRight: Radius.zero),
  TextDirection.ltr => indicatorBorderRadius.copyWith(topLeft: Radius.zero, bottomLeft: Radius.zero)
}

(Regardless of how distant the declaration of borderRadius is.)

If you hit any snags, do let us know!

@bernaferrari
Copy link
Contributor

Hey @pq, another question, what about this code? Is there a way to convert to => while preserving the assert? That's more like a curiosity, hehe. Thanks!

switch (textDirection) {
  case TextDirection.rtl:
    borderRadius = indicatorBorderRadius.copyWith(topRight: Radius.zero, bottomRight: Radius.zero);
  case TextDirection.ltr:
    assert('something');
    borderRadius = indicatorBorderRadius.copyWith(topLeft: Radius.zero, bottomLeft: Radius.zero);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-assist Issues with analysis server assists devexp-server Issues related to some aspect of the analysis server legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

2 participants