Methods in specialized extensions of generic protocols do not call other methods from the same extensions

Originator:ilyapuchka
Number:rdar://23339313 Date Originated:30.10.15
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 7.1
Classification: Reproducible:Always
 
Method from specialized extension of generic protocol that calls another method, defined by the same protocol and implemented in the same specialized extension as well as in general extension, should invoke implementation from the same specialized extension, not from general extension.

Steps to Reproduce:
1. Define some generic protocol that defines type alias, 'methodA()' and 'callA()' (static or instance). 

protocol GenericProtocol {
    typealias Element
    func methodA() -> String
    func callsA() -> String
}

2. Define protocol extension that defines implementation for all kinds of type alias:

extension GenericProtocol {
    func methodA() -> String {
        return "general"
    }
    
    func callsA() -> String {
        return self.methodA().uppercaseString
    }
}

3. Define specialized extension for type alias of some arbitrary type:

extension GenericProtocol where Self.Element == A {
    func methodA() -> String {
        return "special"
    }

    func callsA() -> String {
        return self.methodA.uppercaseString
    }
}

4. Call 'methodA' and 'callA' on instance of this protocol

struct A {}

let structA = GenericStruct<A>()
print(structA.methodA()) // prints "special" - ok
print(structA.callsA()) // prints "GENERAL" - wrong, should be "SPECIAL"

struct B {}
let structB = GenericStruct<B>()
print(structB.methodA()) // prints "general" - ok
print(structB.callMethodA()) // prints "GENERAL" - ok



Expected Results:
Method from specialized extension is called

Actual Results:
Method from general extension is called

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!