Skip to content

Commit ccc6ef8

Browse files
authored
Merge pull request #70978 from tbkka/tbkka-revert-PR68952
Revert #68952 [Casting] Make more casts look inside __SwiftValue
2 parents 114f235 + 4ea5ed1 commit ccc6ef8

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

stdlib/public/runtime/SwiftObject.mm

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,25 +1171,6 @@ static bool isObjCForUnownedReference(void *value) {
11711171
if (object == nullptr)
11721172
return nullptr;
11731173

1174-
#pragma clang diagnostic push
1175-
#pragma clang diagnostic ignored "-Wreceiver-forward-class"
1176-
if ([id_const_cast(object) isKindOfClass:[__SwiftValue class]]) {
1177-
#pragma clang diagnostic pop
1178-
// Source is a `__SwiftValue` container
1179-
// Unwrap, then use the most general casting machine to do the heavy lifting
1180-
auto typeValue = getValueFromSwiftValue(reinterpret_cast<__SwiftValue *>(object));
1181-
const void *result = nullptr;
1182-
if (swift_dynamicCast(reinterpret_cast<OpaqueValue *>(&result),
1183-
const_cast<OpaqueValue *>(typeValue.second),
1184-
typeValue.first,
1185-
targetType,
1186-
DynamicCastFlags::TakeOnSuccess)) {
1187-
return result;
1188-
} else {
1189-
return nullptr;
1190-
}
1191-
}
1192-
11931174
if ([id_const_cast(object) isKindOfClass:class_const_cast(targetType)]) {
11941175
return object;
11951176
}

test/Casting/Casts.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,13 +1065,24 @@ CastsTests.test("Don't put AnyHashable inside AnyObject") {
10651065
}
10661066

10671067
#if _runtime(_ObjC)
1068-
CastsTests.test("__SwiftValue should not be obvious to `is`") {
1068+
// We currently (as of Jan 2024) bridge NSSet to Swift with `x as!
1069+
// Set<NSObject>`, which in turn demands that __SwiftValue successfully cast to
1070+
// NSObject.
1071+
// So this nonsensical behavior can probably never be fixed.
1072+
// (It's nonsense because it implies that every Swift object is derived
1073+
// from NSObject.) See PR #68952 for an early attempt to change it which
1074+
// had to be reverted.
1075+
CastsTests.test("__SwiftValue should not be obvious to `is`")
1076+
.xfail(.always("Probably can never be fixed"))
1077+
.code {
10691078
struct S {}
10701079
let s = S() as AnyObject
10711080
expectFalse(s is NSObject)
10721081
}
10731082
#endif
10741083

1084+
// See above for reasons why this might need to remain broken forever,
1085+
// though I do have some hope for it.
10751086
CastsTests.test("type(of:) should look through __SwiftValue")
10761087
.xfail(.always("Known to be broken"))
10771088
.code {

0 commit comments

Comments
 (0)