Oh, cool! This is exactly the same code I was asking the community to comment out if this is wanted/expected behavior. Unfortunately no reply was given. This is why I suggested a warning if type's method has the same name as such protocol extension method in my current thread "[Pitch] Requiring special keyword to mark protocol implementation methods"

On 19.05.2016 15:30, Krystof Vasa wrote:
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 
<[email protected]> 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
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

.

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to