Looks like a bug according to dispatch rules (here <https://medium.com/ios-os-x-development/swift-protocol-extension-method-dispatch-6a6bf270ba94#.8zlhlu8s6> and here <https://nomothetis.svbtle.com/the-ghost-of-swift-bugs-future?utm_campaign=iOS+Dev+Weekly&utm_medium=web&utm_source=iOS_Dev_Weekly_Issue_203>. Also similar question on SO <http://stackoverflow.com/questions/34847318/swift-protocol-extension-method-dispatch-with-superclass-and-subclass>) It should call dynamic bar implementation
> 20 сент. 2016 г., в 5:11, Zhao Xin via swift-users <[email protected]> > написал(а): > > See below code. > > protocol Foo { > func bar() > } > > extension Foo { > func bar() { > print("I am bar.") > } > } > > class A:Foo { > func output() { > print(type(of:self)) // prints "B". > self.bar() // prints "I am bar." > (self as! B).bar() // prints "I am B." > } > } > > class B:A { > func bar() { > print("I am B.") > } > } > > let b = B() > b.output() > > I thought `self.bar()` would do the same as `(self as! B).bar()`. It didn't. > In my opinion, `type(of:self) is B.type`, so they should be the same, > shouldn't they? > > Zhaoxin > _______________________________________________ > swift-users mailing list > [email protected] > https://lists.swift.org/mailman/listinfo/swift-users
_______________________________________________ swift-users mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-users
