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-7707] EXC_BAD_ACCESS when returning nil before capturing any type inside double closure #50247

Closed
swift-ci opened this issue May 16, 2018 · 2 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7707
Radar rdar://problem/40332620
Original Reporter zackmcbride (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash
Assignee @gottesmm
Priority Medium

md5: bca83a35f84db3c7d86c2d575c3f3ef2

Issue Description:

Example:

func testCrash() -> Any? {

    func capture(closure: () -> Void) {
        closure()
    }

    // implicity unwrap `object` and this won't crash...
    var object: Any
    var aClosure: () -> Void

    if true {
        return nil
    }

    object = ()

    // remove this double closure and it won't crash...
    aClosure = {
        capture {
            print(object)
        }
    }
    //

    return object
}

This is a simplified version of an actual use case. I get a bad access exception when returning nil in the function above, however if the nested closures further down the function are removed it all works correctly.

Also, if I implicitly unwrap `object` in the function above at declaration it will also work correctly.

I tested this with multiple different compiler optimisation levels and in a playground and it failed each time.

@belkadan
Copy link
Contributor

@swift-ci create

@gottesmm
Copy link
Member

This was fixed by:

#16962

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 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 crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

4 participants