Swift: internal type structure affects protocol extension dispatch

Originator:garth
Number:rdar://21967880 Date Originated:23-Jul-2015 01:11 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7 beta 4
Classification:Serious Bug Reproducible:Always
 
Try the code below in a playground. np and dp are of identical formal types, but they dispatch differently, even though neither object has an actual doFoo() implementation of its own.

protocol Foo { func doFoo() }

protocol Qux {}

extension Foo {
    func doFoo() { print("Called default doFoo") }
}

extension Foo where Self: Qux {
    func doFoo() { print("Called Qux-specific doFoo") }
}

class BaseClass: Foo {}
class DerivedClass: BaseClass, Qux {}

class NativeFooQuxClass: Foo, Qux {}

let n = NativeFooQuxClass()
let d = DerivedClass()

n.doFoo() // Calls Qux-specific doFoo - correct
d.doFoo() // Calls Qux-specific doFoo - correct

let np: protocol<Foo, Qux> = n
let dp: protocol<Foo, Qux> = d

np.doFoo() // Calls Qux-specific doFoo - correct
dp.doFoo() // Calls default doFoo - incorrect

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!