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-10060] Not-so-rethrows bug #52463

Closed
stephencelis opened this issue Mar 7, 2019 · 2 comments
Closed

[SR-10060] Not-so-rethrows bug #52463

stephencelis opened this issue Mar 7, 2019 · 2 comments
Assignees
Labels
accepts invalid Bug: Accepts invalid 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-10060
Radar rdar://problem/48994085
Original Reporter @stephencelis
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 4.2

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

md5: 8b6cf9b4c62acd7fdf217f55c75401df

blocks:

  • SR-680 rethrows analysis breaks when wrapped in another rethrows function

Issue Description:

The following code crashes at runtime:

func a(_ f: () throws -> Void, _ fs: [() throws -> Void]) rethrows {
  try f()
  try fs.forEach { try $0() }
}


struct Unit: Error {}


func b() {}
func c() throws { throw Unit() }


a(b, [c]) 
@swift-ci
Copy link
Collaborator

swift-ci commented Mar 9, 2019

Comment by Michael Verges (JIRA)

It seems the intended behavior of functions declared 'rethrows' is to only propagate Errors thrown from the parameter. The parameter '_ fs' is an array, not a closure, so the rethrowing function is not responsible for error handling.

Here is a more explicit example:

struct Unit: Error {}

class Alpha {
    func foo() throws {
        throw Unit()
    }
}

func bar(function: () throws -> Void, alpha: Alpha) rethrows {
    try alpha.foo()
    // ERROR: Call can throw, but the error is not handled; a function declared 'rethrows' may only throw if its parameter does
}

Maybe this bug should be resolved by better diagnosing, like in my example where it explicitly states "a function declared 'rethrows' may only throw if its parameter does".

@belkadan
Copy link
Contributor

Yeah, I don't think this is supposed to be accepted, as useful as it would be. cc @xedin

@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
accepts invalid Bug: Accepts invalid 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