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

[SR-9815] Swift complains about throwing function that isn't one (through @autoclosure) #52233

Closed
weissi opened this issue Jan 30, 2019 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@weissi
Copy link
Member

weissi commented Jan 30, 2019

Previous ID SR-9815
Radar None
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Duplicate
Environment
Apple Swift version 5.0 (swiftlang-1001.0.45.7 clang-1001.0.37.7)
Target: x86_64-apple-darwin18.2.0
ABI version: 0.6
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 4c7ffa11ef7523b4f33477c960de91a6

duplicates:

Issue Description:

this Swift program should just work

struct S {
    func map(_ body: () -> ()) {
        body()
    }
}

func f<T>(_ body: @autoclosure () throws -> T) {
}

func throwing() throws {
}

S().map {
    f(try throwing())
}

however it raises:

test.swift:13:9: error: invalid conversion from throwing function of type '() throws -> ()' to non-throwing function type '() -> ()'
S().map {
        ^

Interestingly, there's a simple workaround:

struct S {
    func map(_ body: () -> ()) {
        body()
    }
}

func f<T>(_ body: @autoclosure () throws -> T) {
}

func throwing() throws {
}

S().map {
    func shouldNotBeNecessary() {
        f(try throwing())
    }
    shouldNotBeNecessary()
}
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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.
Projects
None yet
Development

No branches or pull requests

1 participant