Skip to content

[SR-10308] EXC_BAD_ACCESS crash when capturing self weakly in a convenience initializer #52708

@swift-ci

Description

@swift-ci
Previous ID SR-10308
Radar None
Original Reporter dbeard (JIRA User)
Type Bug
Environment

Xcode Version 10.2 (10E125) / Swift 5.0

macOS version 10.14.4 (18E226)

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

md5: b46c020e08aba8bae2389a3ca0cb2b74

Issue Description:

The following code causes a crash at runtime, but compiles fine:

import UIKit


enum FooType {
    case one
    case two
}


typealias Permutation = () -> (Void)


@objcMembers
class CatalogItem: NSObject {


    var t: FooType
    var permutation: Permutation?


    required init(t: FooType) {
        self.t = t
    }
}


@objcMembers
class Subclass: CatalogItem {
    convenience init() {
        self.init(t: .one)


        self.permutation = { [weak self] in
            print(self?.t)
        }
    }
}


class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        let s = Subclass() // EXC_BAD_ACCESS !
    }
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwarerun-time crashBug → crash: Swift code crashed during execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions