Swift 2b3: spurious “ambiguous” conformance error when conforming w/extension & protocol

Originator:rix.rob
Number:rdar://21784065 Date Originated:11-Jul-2015 11:16 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-beta (7A152u)
Classification:Other Bug Reproducible:Always
 
Summary:
You can conform a type to Hashable when it also conforms to another protocol requiring Equatable, but not if you declare the Hashable conformance in an extension.


Steps to Reproduce:
1. This code:
protocol P: Equatable {}
struct S: P { var hashValue: Int { return 0 } }
func == (_: S, _: S) -> Bool { return true }
extension S: Hashable {}

Expected Results:
should compile

Actual Results:
but doesn’t:
boom.swift:4:14: error: ambiguous implied conformance of 'S' to protocol 'Equatable' (via 'Hashable') requires explicit conformance
extension S: Hashable {}
             ^
boom.swift:4:14: note: implied protocol conformance 'Equatable' here can be made explicit
extension S: Hashable {}
             ^
             Equatable, 
boom.swift:2:8: note: 'S' implicitly conforms to protocol 'Equatable' (via conformance to 'P') here
struct S: P { var hashValue: Int { return 0 } }
       ^

Regression:
Doesn’t happen if you declare S to be Hashable on the line defining it.
Doesn’t happen if you do what the fixit says and declare S to be Equatable on the extension as well.
Doesn’t happen if S does not conform to P.

Notes:
This isn’t ambiguous. It doesn’t have to resolve some typealias to two different types or something; it’s just got to match Self twice (unambiguously, to the same Self!).

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!