[swift-evolution] Proposal SE-0009 Reconsideration
Krystof Vasa
kvasa at icloud.com
Thu May 19 07:30:01 CDT 2016
See this example that demonstrates how it's pretty much unusable (IMHO), since whenever you refer to the instance as to the protocol, the default implementation gets invoked:
protocol MyProtocol { }
extension MyProtocol {
func getInt() -> Int {
return 0
}
}
class MyClass: MyProtocol {
func getInt() -> Int {
return 1
}
}
let instance = MyClass()
instance.getInt() // 1
var anyInstance: MyProtocol = instance
anyInstance.getInt() // 0 !!!!!!!
Since anyInstance is of MyProtocol type, you get the default implementation (no dynamic dispatch).
Krystof
> On May 19, 2016, at 2:22 PM, Vladimir.S via swift-evolution <swift-evolution at swift.org> wrote:
>
> On 19.05.2016 0:01, Michael Peternell wrote:
>>> Not Fun To Debug bits (similar to the dispatching rules of protocol
>>> extensions default methods).
>> There are dispatching rules of protocol extension default methods? I
>> thought the methods are selected randomly... just kidding -
>
> [offtopic]
> Could you please describe the joke and the problem of 'dispatching rules of protocol extensions default methods'? Want to clarify this for myself. Thank you.
> [/offtopic]
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list