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-2979] 'rethrows' function with non-throwing default requires 'try' #45569

Closed
natecook1000 opened this issue Oct 18, 2016 · 1 comment
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@natecook1000
Copy link
Member

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

swift/master

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

md5: cb9111257bd7df15f0c96606bf6fc98a

duplicates:

  • SR-1534 Error: Call is to rethrows function, but a defaulted argument function can throw

Issue Description:

If I write a rethrowing function that takes a possibly throwing closure and provide a non-throwing default value, I have to use 'try' when calling that function without an argument. Is this the right behavior? The compiler should be aware that the default closure doesn't throw, so it would be nice if the "default" function call wasn't marked as rethrowing:

func foo(_ f: () throws -> Void = { print("Hello!") }) rethrows {
    try f()
}

foo({ print("Hey!") })
// Hey!
foo()
// error: call can throw but is not marked with 'try'
// note: call is to 'rethrows' function, but argument function can throw
try foo()
// Hello!
@belkadan
Copy link
Contributor

Currently default arguments are provided by the caller, not the callee, which means that the default value could change in a later version of the library. That's the reasoning behind the current rule, anyway—clearly in this case the function is in the same module.

We should fix this at the point where we change default arguments to be inlined emitted into the current module.

@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

2 participants