Skip to content

[SR-6184] Not expected behavior in Generic Type's Protocol Extension #48736

@swift-ci

Description

@swift-ci
Previous ID SR-6184
Radar None
Original Reporter 100mango (JIRA User)
Type Bug
Environment

Xcode 9.0

Swift4

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 0bf8e790977c4215c3710b9e3a95f618

Issue Description:

extension MyProtocol {
    func log()
}
extension MyProtocol {
    func log() {
        print("MyProtocol default implementation")
    }
}

class MyGenericClass<T> : MyProtocol {
    let t: T
    init(_ t: T) {self.t = t}
}

extension MyProtocol where Self==MyGenericClass<Int> {
    func log() {
        print("MyProtocol where MyGenericClass<Int>")
    }
}

func logByProtocol(_ p: MyProtocol) {
    p.log()
}

let myGenericClassNumber = MyGenericClass(1)
let myGenericClassString = MyGenericClass("1")

myGenericClassNumber.log()//expect "MyGenericClass<Int>"   true
myGenericClassString.log()//expect "MyProtocol default implementation"   true

logByProtocol(myGenericClassNumber)//expect "MyGenericClass<Int>", But print "MyProtocol default implementation"   wrong

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions