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 {
439
439
guard let kind = _SwiftTypePreservingNSNumberTag (
440
440
rawValue: Int ( _swift_Foundation_TypePreservingNSNumberGetKind ( self ) )
441
441
) else {
442
+ if let nsDecimalNumber: NSDecimalNumber = self as? NSDecimalNumber {
443
+ return AnyHashable ( nsDecimalNumber as Decimal )
444
+ }
442
445
return nil
443
446
}
444
447
switch kind {
Original file line number Diff line number Diff line change @@ -30,8 +30,6 @@ @interface _SwiftTypePreservingNSNumber : NSNumber
30
30
SwiftDouble = 4 ,
31
31
SwiftCGFloat = 5 ,
32
32
SwiftBool = 6
33
- // FIXME(id-as-any): add support for NSDecimal and
34
- // Foundation.Decimal.
35
33
};
36
34
37
35
@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