nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.92k stars 639 forks source link

'hoistTry' rule has an issue in strings #1403

Closed foscomputerservices closed 1 year ago

foscomputerservices commented 1 year ago

Issue

There seems to be an issue when hoisting try out of expressions embedded in strings. Take the following code for example:

public struct TestHoistTry {
    public init() throws {
        print("Hello \(try Foo.tryMe())")
    }
}

struct Foo {
    static func tryMe() throws -> String { ", World!" }
}

After running swiftlint we get the following:

public struct TestHoistTry {
    public init() throws {
        print("Hello \try (Foo.tryMe())") // <- try was lifted to the \
    }
}

enum Foo {
    static func tryMe() throws -> String { ", World!" }
}

Environment

% swiftformat --version 0.51.2

% swift --version swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51) Target: arm64-apple-macosx13.0

% xcodebuild -version Xcode 14.2 Build version 14C18

nicklockwood commented 1 year ago

This has already been reported and will be fixed in the next release. Thanks!

nicklockwood commented 1 year ago

@foscomputerservices fixed in 0.51.3