nicklockwood / SwiftFormat

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

SwiftFormat breaks optional generic return value #1441

Closed lhunath closed 1 year ago

lhunath commented 1 year ago

Given the following code:

func foo() -> Optional<some Publisher<String, Never>> {
    fatalError()
}

SwiftFormat will rewrite as:

func foo() -> some Publisher<String, Never>? {
    fatalError()
}

This results in illegal Swift code:

Use of protocol 'Publisher' as a type must be written 'any Publisher'

(The error message is misleading, the correct code was the original; do not change some to any)

$ 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
nicklockwood commented 1 year ago

I think the issue is that it needs to be written as (some Publisher<String, Never>)?.

Obviously swiftformat shouldn't introduce a breaking change here, but until the bug is fixed, manually adding the parens might be a workaround?

nicklockwood commented 1 year ago

@lhunath fixed in 0.51.9