protocol extension bug?

A simple playground use case:


protocol Timeout {
   var  timeout: Double { get }
}
extension Timeout {
    var timeout: Double { return 30.0}
}
class A: Timeout { }
class B: Timeout {
    var timeout: Double { return 0 }
}
class C: A {
    var timeout: Double { return 0 }
}
func testTimeout(obj: AnyObject) {
    if let o = obj as? Timeout where o.timeout > 0 {
        print("\(o) has timeout value: \(o.timeout)")
    } else {
        print("\(obj) has NO timeout")
   
    }
}
/: A and B gave expected result */
testTimeout(A())
A has timeout value: 30.0

testTimeout(B())
B has NO timeout

/: expect C to say no timeout, but instead it gave Timeout extension's value! */
testTimeout(C())
C has timeout value: 30.0


It shows when C derive from A, which used Timeout protocol extension's default timeout property, C lost the ability to provide its own implementation for the protocol... This sounded like a bug to me...

Yes, it is a bug, please file a radar for this. Your code originally does not even work in Xcode Beta 1 which crashes with Segmentation Fault 11 unless class C is removed.

yup, done that: rdar://21543495 Swift Protocol Extension Override Bug

protocol extension bug?
 
 
Q