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

Async let does not preserve typed throw #76169

Open
finestructure opened this issue Aug 30, 2024 · 1 comment
Open

Async let does not preserve typed throw #76169

finestructure opened this issue Aug 30, 2024 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@finestructure
Copy link

Description

According to SE-0413, async let should preserve the error type of typed throws.

However, this does not seem to be the case in Xcode 16.0 beta 6 (16A5230g).

Reproduction

struct AppError: Error { }

func f() async throws(AppError) -> Int { 42 }

func test() async throws(AppError) -> Int {
    async let a = f()
    return try await a
}

fails to compile with

error: Error - typed throws.xcplaygroundpage:119:26: thrown expression type 'any Error' cannot be converted to error type 'AppError'
        return try await a
                         ^

Expected behavior

try await a should satisfy throws(AppError) of the function.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx15.0

Additional information

No response

@finestructure finestructure added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Aug 30, 2024
@finestructure finestructure changed the title Async let does not preserver typed throw Async let does not preserve typed throw Aug 30, 2024
@JessyCatterwaul
Copy link

For all other purposes, I've been using forceCastError from Cast. But

Capturing 'async let' variables is not supported

If you come up with better than explicit do/catch, please post it here!

do { return try await a }
catch { throw error as! AppError }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

2 participants