nicklockwood / SwiftFormat

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

Incorrect removal of return in if within a failable init #1525

Closed yonaskolb closed 10 months ago

yonaskolb commented 11 months ago

Using SwiftFormat 0.52.4 with swiftversion set to 5.9, and the redundantReturn rule.

SwiftFormat incorrectly removes the return here leading to a compiler error 'nil' requires a contextual type

init?(optionalHex: String?) {
    if let optionalHex {
        self.init(hex: optionalHex)
    } else {
-        return nil
+        nil
    }
}

Will be removing this code anyway, as it serves no real purpose, but wanted to open an issue to let you know

nicklockwood commented 10 months ago

@yonaskolb fixed in 0.52.5. Thanks for the report!