File tree Expand file tree Collapse file tree 3 files changed +28
-2
lines changed
stdlib/public/SDK/Foundation Expand file tree Collapse file tree 3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -439,6 +439,9 @@ extension NSNumber : _HasCustomAnyHashableRepresentation {
439439 guard let kind = _SwiftTypePreservingNSNumberTag (
440440 rawValue: Int ( _swift_Foundation_TypePreservingNSNumberGetKind ( self ) )
441441 ) else {
442+ if let nsDecimalNumber: NSDecimalNumber = self as? NSDecimalNumber {
443+ return AnyHashable ( nsDecimalNumber as Decimal )
444+ }
442445 return nil
443446 }
444447 switch kind {
Original file line number Diff line number Diff line change @@ -30,8 +30,6 @@ @interface _SwiftTypePreservingNSNumber : NSNumber
3030 SwiftDouble = 4 ,
3131 SwiftCGFloat = 5 ,
3232 SwiftBool = 6
33- // FIXME(id-as-any): add support for NSDecimal and
34- // Foundation.Decimal.
3533};
3634
3735@implementation _SwiftTypePreservingNSNumber {
Original file line number Diff line number Diff line change 1+ // RUN: %target-run-simple-swiftgyb
2+ // REQUIRES: executable_test
3+ // REQUIRES: objc_interop
4+
5+ import Foundation
6+ import StdlibUnittest
7+
8+ let NSDecimalNumberTests = TestSuite("NSDecimalNumber")
9+
10+ NSDecimalNumberTests.test("AnyHashable containing Foundation.Decimal") {
11+ let values = [
12+ NSDecimalNumber(string: "10.0"),
13+ NSDecimalNumber(string: "20.0"),
14+ NSDecimalNumber(string: "20.0"),
15+ ]
16+ let anyHashables = values.map(AnyHashable.init)
17+ expectEqual("Decimal", String(anyHashables[0].base.dynamicType))
18+ expectEqual("Decimal", String(anyHashables[1].base.dynamicType))
19+ expectEqual("Decimal", String(anyHashables[2].base.dynamicType))
20+ expectNotEqual(anyHashables[0], anyHashables[1])
21+ expectEqual(anyHashables[1], anyHashables[2])
22+ }
23+
24+ runAllTests()
25+
You can’t perform that action at this time.
0 commit comments