Skip to content

Commit f7ab029

Browse files
committed
Add a test to verify that AnyHashable gets eagerly unwrapped
To allow for better compiler optimizations, the runtime should guarantee that AnyHashable does not get boxed unnecessarily. In particular, there was a concern that casting an `AnyHashable` containing a class reference to `AnyObject` would box the AnyHashable instead of unwrapping it. Further testing shows that the runtime is NOT doing this unnecessary boxing at current. Resolves rdar://90269352
1 parent 8c7f331 commit f7ab029

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/Casting/Casts.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,4 +1036,14 @@ CastsTests.test("Do not overuse __SwiftValue (non-ObjC)") {
10361036
expectTrue(Foo() is AnyObject)
10371037
}
10381038

1039+
CastsTests.test("Don't put AnyHashable inside AnyObject") {
1040+
class C: Hashable {}
1041+
let a = C()
1042+
let b = AnyHashable(a)
1043+
let c = a as! AnyObject
1044+
expectTrue(a === c)
1045+
let d = c as! C
1046+
expectTrue(a === d)
1047+
}
1048+
10391049
runAllTests()

0 commit comments

Comments
 (0)