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

Unexpected compiler error when passing function as parameter to rethrows function #74305

Open
Wouter01 opened this issue Jun 11, 2024 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features typed throws Feature → error handling → throws & rethrows: Typed throws

Comments

@Wouter01
Copy link

Wouter01 commented Jun 11, 2024

Description

When passing a function as a parameter to a rethrows function instead of providing a closure, an unexpected compiler error is thrown, stating that the function call can throw, which is not the case. Calling the same function from within a closure is ok. The error does not seem to occur when @MainActor attribute is removed from the function. This error does not occur on Swift 5.10.

Reproduction

@MainActor
func doSomethingOne() {
    func test(_ tab: Int) {}

    [1,2,3].forEach(test) // Call can throw, but it is not marked with 'try' and the error is not handled
                          // Call is to 'rethrows' function, but argument function can throw
}

@MainActor
func doSomethingTwo() {
    func test(_ tab: Int) {}

    for i in [1,2,3] {
        test(i) // OK
    }
}

func doSomethingThree() {
    func test(_ tab: Int) {}

    [1,2,3].forEach(test)  // OK
}

Expected behavior

The code compiles

Environment

swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx15.0

Additional information

Edit: This only seems to occur when Swift 6 language mode is enabled

@Wouter01 Wouter01 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Jun 11, 2024
@nh7a
Copy link

nh7a commented Jul 10, 2024

This is still the case with Xcode 16 beta 3.

swift-driver version: 1.111.2 Apple Swift version 6.0 (swiftlang-6.0.0.5.15 clang-1600.0.22.6)

@hborla hborla added concurrency Feature: umbrella label for concurrency language features typed throws Feature → error handling → throws & rethrows: Typed throws and removed triage needed This issue needs more specific labels labels Jul 14, 2024
@DagAgren
Copy link

Seeing the same issue. Also, at least in my case changing it to [1,2,3].forEach { test($0) } also makes the error go away, so this seems like a clear bug.

@AdamCmiel
Copy link

Seeing the same behavior building on ce29eca81a5

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. concurrency Feature: umbrella label for concurrency language features typed throws Feature → error handling → throws & rethrows: Typed throws
Projects
None yet
Development

No branches or pull requests

5 participants