Swift: infinite recursion with subclass + willSet + didSet + protocols + optional chaining

Originator:jtbandes
Number:rdar://23397859 Date Originated:11/4/2015
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
The following code produces an infinite loop, but shouldn't:

Steps to Reproduce:

protocol ModelProtocol {
    var property: String { get }
}

class ConcreteModel: ModelProtocol {
    let property = "I'm a ConcreteModel"
}

class Base {
    var model: ModelProtocol? {
        willSet {
            print("Base.model.willset")
        }
        didSet {
            print("Base.model.didset")
        }
    }
}

class Derived: Base {
    
    override var model: ModelProtocol? {
        willSet {
            print("Derived.model.willset")
        }
        didSet {
            print("entering Derived.model.didset")
            _ = model?.property  // causes an infinite loop in Xcode 7.1
            print("finished Derived.model.didset")
        }
    }
}


let d = Derived()
d.model = ConcreteModel()



Expected Results:
No loop.

Actual Results:
Infinite loop.

WORKAROUND:

            let m = model   // breaks the cycle; no more infinite loop
            _ = m?.property


Version:
10.10.5 (14F1021)

Notes:


Configuration:
Xcode 7.1

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!