Environment
Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37)
Target: x86_64-apple-macosx10.9
Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1)
Target: x86_64-apple-darwin17.5.0
Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3)
Target: x86_64-apple-darwin18.0.0
Additional Detail from JIRA
| | |
|------------------|-----------------|
|Votes | 0 |
|Component/s | Compiler |
|Labels | Bug, ClangImporter |
|Assignee | None |
|Priority | Medium |
md5: 0824e58f4798fbbf56cc0dc19a2d115f
Issue Description:
When attempting to use `Protocol` as a key-type in a Swift dictionary an error is produced when it is directly included (add2).
If used as a restriction on a generic type (add1) it compiles fine.
NOTE: If the generic function is made to consider Protocol & Hashable, Swift versions \< 4.1 reported a warning: "Redundant conformance constraint 'T' : 'Hashable'"
import Foundation
func add1<T: Protocol>(contentsOf: [T: AnyObject]) {
// OK!
}
func add2(contentsOf: [Protocol: AnyObject]) {
// Error: Type 'Protocol' does not conform to protocol 'Hashable'
}
func add3<T: Protocol & Hashable>(contentsOf: [T: AnyObject]) {
// Warning: Redundant conformance contstraint 'T': 'Hashable'
// Only manifests in Swift < 4.1
}
Environment
Apple Swift version 4.0 (swiftlang-900.0.65 clang-900.0.37) Target: x86_64-apple-macosx10.9 Apple Swift version 4.1 (swiftlang-902.0.48 clang-902.0.37.1) Target: x86_64-apple-darwin17.5.0 Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3) Target: x86_64-apple-darwin18.0.0Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, ClangImporter | |Assignee | None | |Priority | Medium | md5: 0824e58f4798fbbf56cc0dc19a2d115fIssue Description:
When attempting to use `Protocol` as a key-type in a Swift dictionary an error is produced when it is directly included (add2).
If used as a restriction on a generic type (add1) it compiles fine.
NOTE: If the generic function is made to consider Protocol & Hashable, Swift versions \< 4.1 reported a warning: "Redundant conformance constraint 'T' : 'Hashable'"