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-11669] Calling function with throwing autoclosure parameter in another closure. #54078

Closed
zienag opened this issue Oct 25, 2019 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@zienag
Copy link

zienag commented Oct 25, 2019

Previous ID SR-11669
Radar None
Original Reporter @zienag
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
Target: x86_64-apple-darwin18.6.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 67a57935eb77124209fdd9d2379004f1

duplicates:

Issue Description:

I have a test that checks that some processing function doesn't throw, and this function is called inside some "completion" like closure:

me.request {
  XCTAssertNoThrow(try process($0))
}

The problem is that compiler thinks that I'm trying to call `me.request` with throwing closure, and doesn't allow me to do so. While it's completely valid thing in regular function body, I think that's a bug.

Basic code to reproduce:

func request(_: () -> Void) {}
func process() throws {}
func check(_: @autoclosure () throws -> Void) {}

// Invalid conversion
// from throwing function of type '() throws -> ()'
// to non-throwing function type '() -> Void'
request {
  check(try process())
}

// Completely valid
func foo() {
  check(try process())
}
@theblixguy
Copy link
Collaborator

I think this is a known issue (need to hunt for the SR). In the meantime, here's a workaround:

request {
  func workaround() {
    check(try process())
  }
  workaround()
}

@belkadan
Copy link
Contributor

Found it for you, Suyash.

@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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants