diff --git a/stdlib/public/core/Mirror.swift b/stdlib/public/core/Mirror.swift index a8aee9408fa0b..70b3723b25086 100644 --- a/stdlib/public/core/Mirror.swift +++ b/stdlib/public/core/Mirror.swift @@ -905,6 +905,43 @@ extension DictionaryLiteral : RandomAccessCollection { } } +extension DictionaryLiteral : Equatable where Key: Equatable, Value : Equatable { + @_inlineable // FIXME(sil-serialize-all) + public static func ==(lhs: DictionaryLiteral, rhs: DictionaryLiteral) -> Bool { + let lhsCount = lhs.count + if lhsCount != rhs.count { + return false + } + // We know that lhs.count == rhs.count, compare element wise. + for idx in 0.. Issue applies to DictionaryLiteral too + var result: Int = 0 + for element in self { + let elementHashValue = _combineHashValues(element.key.hashValue, element.value.hashValue) + result = _combineHashValues(result, elementHashValue) + } + return result + } +} + extension String { /// Creates a string representing the given value. /// diff --git a/test/stdlib/DictionaryLiteral.swift b/test/stdlib/DictionaryLiteral.swift index 8fc3c8875060d..ceb2c0f18a647 100644 --- a/test/stdlib/DictionaryLiteral.swift +++ b/test/stdlib/DictionaryLiteral.swift @@ -54,3 +54,12 @@ expectType(DictionaryLiteral.self, &hetero1) var hetero2: DictionaryLiteral = ["a": 1 as NSNumber, "b": "Foo" as NSString] expectType(DictionaryLiteral.self, &hetero2) + +let instances: [DictionaryLiteral] = [ + [1: "a", 1: "a", 2: "b"], + [1: "a", 2: "b", 1: "a"], + [2: "b", 1: "a", 1: "a"], + [1: "a", 1: "a", 1: "a"] +] +checkEquatable(instances, oracle: { $0 == $1 }) +checkHashable(instances, equalityOracle: { $0 == $1 })