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

Removing return in front of try await #1818

Open
knutanderss opened this issue Aug 14, 2024 · 2 comments
Open

Removing return in front of try await #1818

knutanderss opened this issue Aug 14, 2024 · 2 comments
Labels

Comments

@knutanderss
Copy link

Hi, we had an instance in our codebase where SwiftFormat removed return as redundant in front of try await withCheckedThrowingContinuation { ... }, which caused a type error. The outer function returns Void, and withCheckedThrowingContinuation is generic on its return type, so without return the compiler is not able to infer that the generic parameter should be Void too.

It seems perhaps that return is not redundant in front of try await ...?

Anyway, disabling redundantReturn for that line works for now.

@nicklockwood
Copy link
Owner

@knutanderss I'm having a little bit of trouble visualizing the scenario you are talking about. Is it something like this?

func voidFunc() -> Void {
    return try await withCheckedThrowingContinuation { ... }
}

If not, perhaps you could provide a code example?

@Smponias
Copy link

@nicklockwood Some thing like this:

func abc() async throws {
    return try await withCheckedThrowingContinuation { continuation in
        DispatchQueue.main.async {
            someFunctionCall() { result, error in
                if let error {
                    continuation.resume(throwing: error)
                } else if let result {
                    continuation.resume()
                }
            }
        }
    }
}

If you remove the return you will get: Generic parameter 'T' could not be inferred

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

3 participants