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

improper removal of return #1749

Open
nysander opened this issue Jul 3, 2024 · 2 comments
Open

improper removal of return #1749

nysander opened this issue Jul 3, 2024 · 2 comments
Labels

Comments

@nysander
Copy link

nysander commented Jul 3, 2024

     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
Copy link
Owner

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.

@nysander
Copy link
Author

nysander commented Jul 8, 2024

returning explicit void stopped return from being removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants