nicklockwood / SwiftFormat

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

improper removal of return #1749

Open nysander opened 4 days ago

nysander commented 4 days ago
     let completion: AddItemCompletionBlock? = { [unowned self] (success: Bool, serialNumber: SerialNumber?) in
            Task { @MainActor in
                if let serialNumber,
                   let item = itemRepository.fetch(serialNumber: serialNumber) {
                    self.determineViewToShow(with: item, refresh: true)
                    self.popToHomeScreen(with: serialNumber, refresh: success)
                } else {
                    self.popToHomeScreen()
                }
            }
            return // < THIS IS REMOVED and causes crash
        }

my config:

  --exclude Package.swift

--disable wrapMultilineStatementBraces
--disable unusedArguments
--disable trailingCommas
--disable strongOutlets
--disable preferForLoop

--enable blankLineAfterImports
--enable isEmpty,
--enable wrapEnumCases,
--enable wrapSwitchCases
--enable redundantProperty
--enable blankLineAfterSwitchCase
--enable organizeDeclarations

--patternlet inline
--indentcase true
--indent 4
--emptybraces spaced
--ranges no-space
--self init-only
nicklockwood commented 15 hours ago

I think the issue here is that by removing the return, the closure type is being changed to implicitly return a Task instead. I'm not sure why that crashes rather than being a compilation error though - might be a bug in the Swift compiler?

In any case, a workaround for now might be to add an explicit -> Void to the return type? Or if that doesn't work, adding:

// swiftformat:disable:next redundantReturn

Above the return line should solve it until I can find a fix.