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-13051] swift-format changes type of variable in declaration, breaks code #318

Closed
swift-ci opened this issue Jun 19, 2020 · 1 comment
Assignees
Labels
bug Something isn't working swift-format

Comments

@swift-ci
Copy link

Previous ID SR-13051
Radar None
Original Reporter wneumann (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

swift --version
Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.5.0

swift-format --version
0.50200.1

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

md5: b9d2e03cbe33ec845d278c552c6251f9

Issue Description:

Given this code:

  public static func either<B>(_ pa: Parser, _ pb: Parser<B>) -> Parser<Either<A, B>> {
       Parser<Either<A, B>> { str in
           var strX = str[...], err: ErrStr
           switch pa.run(&strX) {
           case let .success(a):
               str = strX
               return .success(.left(a))
           case .failure(let errA): err = errA
           }
           switch pb.run(&strX) {
           case .success(let b):
               str = strX
               return .success(.right(b))
           case .failure(let errB): return .failure(ErrStr("\(err) and \(errB)"))
           }
       }
   }

swift-format trips on the rule: "warning: [OneVariableDeclarationPerLine]: split variable binding into multiple declarations" and converts the code to:

  public static func either<B>(_ pa: Parser, _ pb: Parser<B>) -> Parser<Either<A, B>> {
    Parser<Either<A, B>> { str in
      var strX: ErrStr = str[...]
      var err: ErrStr
      switch pa.run(&strX) {
      case let .success(a):
        str = strX
        return .success(.left(a))
      case .failure(let errA): err = errA
      }
      switch pb.run(&strX) {
      case .success(let b):
        str = strX
        return .success(.right(b))
      case .failure(let errB): return .failure(ErrStr("\(err) and \(errB)"))
      }
    }
  }

The problem here is that swift-format is adding the ErrStr type annotation to the declaration of strX on the third line, changing the type from Substring to ErrStr and breaking the code.

This is the current version of swift-format cloned and built from GitHub today, June 19, 2020.

@allevato
Copy link
Collaborator

allevato commented Jul 9, 2020

This was fixed in master by #208.

@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
This issue was closed.
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

No branches or pull requests

2 participants