Using Class-Only protocols in Swift causes ARC to de-initialise objects incorrectly

Originator:ivanchoo.private
Number:rdar://18287447 Date Originated:
Status:Open Resolved:Open
Product:iOS SDK Product Version:iOS 8
Classification:Bug Reproducible:Yes
 
Summary:
Objects that implements Class-Only protocols are de-initialise while having active references. This undefined behaviour does not manifest while using a normal protocol.

Steps to Reproduce:
1. Create a Single View Application for iOS in Xcode
2. Replace the ViewController.swift with the attached file
3. Run the code in the Simulator
4. The console log will show the deinit message of the object that implements the Class-Only protocol

Expected Results:
Objects that have active references should not de-initialise.

Actual Results:
Classes that implements Class-Only protocol should not be de-initialised while having active references.

Version:
iOS 8

Notes:


Configuration:
Xcode Version 6.0 (6A313)

Attachments:
'ViewController.swift' was successfully uploaded.

-------- ViewController.swift ----------


import UIKit

protocol FooProtocol {
    var name: String { get }
}

protocol BarProtocol: class {
    var name: String { get }
}

class Foo: FooProtocol {
    
    let name: String = "Foo"
    
    deinit {
        println("\(name) deinit")
    }
}

class Bar: BarProtocol {
    
    let name: String = "Bar"
    
    deinit {
        println("\(name) deinit")
    }
}

class Container {
    
    let foo: FooProtocol = Foo()
    let bar: BarProtocol = Bar()
}

class ViewController: UIViewController {

    let container = Container()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        test(container.foo)
        test(container.bar)
    }
    
    func test(bar: BarProtocol) {
        println("Test: \(bar.name)")
    }
    
    func test(foo: FooProtocol) {
        println("Test: \(foo.name)")
    }


}

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!