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-5586] 'rethrows' function used as value requires 'try' #48158

Closed
stephencelis opened this issue Jul 30, 2017 · 6 comments
Closed

[SR-5586] 'rethrows' function used as value requires 'try' #48158

stephencelis opened this issue Jul 30, 2017 · 6 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@stephencelis
Copy link
Contributor

Previous ID SR-5586
Radar None
Original Reporter @stephencelis
Type Bug
Status Resolved
Resolution Invalid
Environment

Xcode 9 beta 4 + 2017-07-29 development snapshot

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

md5: 08f11884834d43f98123ce4a93f47978

is blocked by:

  • SR-5251 Generic Sequence Function Compilation Fails

Issue Description:

extension Optional {
  public func apply<A>(_ f: ((Wrapped) -> A)?) -> A? {
    return f.flatMap(self.map)
  }
}

Call can throw, but it is not marked with 'try' and the error is not handled

@belkadan
Copy link
Contributor

I don't think we're likely to do anything about this. The compiler can't see how flatMap is going to use its argument, and so it has to assume it might throw. (For this general reason, rethrows functions always decay into throws functions when you use them as a value.)

@stephencelis
Copy link
Contributor Author

Doesn't the throwsrethrows pairing give the compiler enough to know that if the function passed isn't marked throws then the try isn't needed? (I guess this wouldn't be the case for functions with multiple higher-order arguments.) If I define non-throws overloads for map and flatMap it surprisingly seems to work (I was worried about creating ambiguity).

@belkadan
Copy link
Contributor

I haven't thought it through whether rethrows on the called function means that rethrows on a function argument can be dropped.

@belkadan
Copy link
Contributor

cc @rudkx

@rudkx
Copy link
Member

rudkx commented Jan 19, 2018

{map} is declared {rethrows}. We do not know what {map} is going to be applied to so we have to assume it can throw, and thus the overall expression can throw.

@rudkx
Copy link
Member

rudkx commented Jan 19, 2018

Please feel free to reopen if you think there is something else going on here that I'm missing.

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

3 participants