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-9731] @autoclosure dealing throws declaration wiredly #52165

Closed
swift-ci opened this issue Jan 23, 2019 · 0 comments
Closed

[SR-9731] @autoclosure dealing throws declaration wiredly #52165

swift-ci opened this issue Jan 23, 2019 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-9731
Radar None
Original Reporter lolicon (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
Target: x86_64-apple-darwin18.0.0

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

md5: 9e5251ad46a4b3a91273acd21faf71de

duplicates:

Issue Description:

below shows a reduced sample, the compiler attempt to hoist @autoclosure content as a statement of the call-site which leads a compile error, this is not the designated behavior

the commentted line will raise an `Invalid conversion from throwing function of type '() throws -> Either<Error, Int>' to non-throwing function type '() -> _'` error

public enum Either<L, R> {
  case Left(L)
  case Right(R)
 }

func mayThrow() throws -> Int {
  return 100
}

func measureNano<T>(_ block: ()-> T) -> (Int,T) {
   return (0, block())
}

func rescue<T>(_ block: @autoclosure () throws -> T) -> Either<Error,T> {
 do { 
    return .Right(try block()) 
 }
 catch{
    return .Left(error) 
  }
}

func main() {
  measureNano  { // this line will raise a compiler error 
    rescue(try mayThrow()) 
  }
}
@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

1 participant