Skip to content
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

[SR-14438] swift-format makes certain 'switch'-es invalid #310

Closed
karwa opened this issue Apr 1, 2021 · 1 comment · Fixed by #400
Closed

[SR-14438] swift-format makes certain 'switch'-es invalid #310

karwa opened this issue Apr 1, 2021 · 1 comment · Fixed by #400
Assignees
Labels
bug Something isn't working swift-format

Comments

@karwa
Copy link
Contributor

karwa commented Apr 1, 2021

Previous ID SR-14438
Radar None
Original Reporter @karwa
Type Bug
Environment

swift-format 0.50300.

Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28).

Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee None
Priority Medium

md5: 64b6228609f17a16f328087e06a7070d

Issue Description:

func test() {
  enum Test {
    case a
    case b
    case c
    var someProperty: Bool { true }
  }
  var val: Test? = nil
  switch val {
  case .some(let value) where v.someProperty: fallthrough
  case .a?, .b?: return true
  default: return false
  }
}

Is formatted by swift-format to:

func test() {
  enum Test {
    case a
    case b
    case c
    var someProperty: Bool { true }
  }
  var val: Test? = nil
  switch val {
  case .some(let value) where v.someProperty, .a?, .b?: return true
  default: return false
  }
}

Which breaks the code ('value must be bound in every pattern')

@typesanitizer
Copy link

cc @allevato

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
@allevato allevato self-assigned this Sep 16, 2022
allevato added a commit to allevato/swift-format that referenced this issue Sep 16, 2022
*   Don't merge cases involving value binding patterns. For example,
    `case .foo(let x)` can only be merged with other cases that match
    compatible patterns and types. Since we don't know those types,
    play it safe and don't merge them at all.
*   Allow merging of cases before a `default` or `@unknown default`,
    but only into their own `fallthrough`-only case, never into the
    `default` itself.
*   In lint mode, don't diagnose that a case before a `default` should
    be merged into the `default`.

Fixes apple#310.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working swift-format
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants