File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -1093,6 +1093,22 @@ static bool isObjCForUnownedReference(void *value) {
1093
1093
if (object == nullptr )
1094
1094
return nullptr ;
1095
1095
1096
+ if ([id_const_cast (object) isKindOfClass: [__SwiftValue class ]]) {
1097
+ // Source is a `__SwiftValue` container
1098
+ // Unwrap, then use the most general casting machine to do the heavy lifting
1099
+ auto typeValue = getValueFromSwiftValue (reinterpret_cast <__SwiftValue *>(object));
1100
+ const void *result = nullptr ;
1101
+ if (swift_dynamicCast (reinterpret_cast <OpaqueValue *>(&result),
1102
+ const_cast <OpaqueValue *>(typeValue.second ),
1103
+ typeValue.first ,
1104
+ targetType,
1105
+ DynamicCastFlags::TakeOnSuccess)) {
1106
+ return result;
1107
+ } else {
1108
+ return nullptr ;
1109
+ }
1110
+ }
1111
+
1096
1112
if ([id_const_cast (object) isKindOfClass: class_const_cast (targetType)]) {
1097
1113
return object;
1098
1114
}
Original file line number Diff line number Diff line change @@ -1064,4 +1064,21 @@ CastsTests.test("Don't put AnyHashable inside AnyObject") {
1064
1064
expectTrue ( a === d)
1065
1065
}
1066
1066
1067
+ #if _runtime(_ObjC)
1068
+ CastsTests . test ( " __SwiftValue should not be obvious to `is` " ) {
1069
+ struct S { }
1070
+ let s = S ( ) as AnyObject
1071
+ expectFalse ( s is NSObject )
1072
+ }
1073
+ #endif
1074
+
1075
+ CastsTests . test ( " type(of:) should look through __SwiftValue " )
1076
+ . xfail ( . always( " Known to be broken " ) )
1077
+ . code {
1078
+ struct S { }
1079
+ let s = S ( ) as AnyObject
1080
+ let t = " \( type ( of: s) ) "
1081
+ expectEqual ( t, " S " ) // Fails: currently says `__SwiftValue`
1082
+ }
1083
+
1067
1084
runAllTests ( )
You can’t perform that action at this time.
0 commit comments