Skip to content

Commit a22f57b

Browse files
committed
Restore Prior Behavior for NSCopying Lookup in Subscript Type Mapping
Bear with me, this is going to get weird. Swift has to import -[NSDictionary objectForKeyedSubscript:] with a special NSCopying bound that otherwise does not appear in source. This involves the clang importer looking very specifically for this selector, on this type, in Foundation. The old behavior was to try to run a type lookup for NSCopying then bail if that failed. With the introduction of explicit existentials, the failure path changed to check if the existential itself is NULL. That's currently an impossible condition. What instead happens is that if your SDK is broken we submit a NULL NSCopying primitive to the ExistentialType constructor and crash in +asserts compilers. Quite how you wind up in this position in real world setups is a mystery - if the Foundation module were somehow corrupt, or the module cache returned an incoherent type entry lacking a definition for NSCopying we could crash here. In fact, you can replicate this crash by removing the definition for NSCopying in the mock SDK and leaving behind a forward declaration! Since this condition is not representative of an expected setup, restoring the old behavior sans test is probably the right way to go. rdar://91062370
1 parent 4a5f4d1 commit a22f57b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,9 +2817,10 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
28172817
if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
28182818
paramTy->isObjCIdType()) {
28192819
// Not using `getImportTypeAttrs()` is unprincipled but OK for this hack.
2820-
swiftParamTy = ExistentialType::get(SwiftContext.getNSCopyingType());
2821-
if (!swiftParamTy)
2820+
auto nsCopying = SwiftContext.getNSCopyingType();
2821+
if (!nsCopying)
28222822
return {Type(), false};
2823+
swiftParamTy = ExistentialType::get(nsCopying);
28232824
if (optionalityOfParam != OTK_None)
28242825
swiftParamTy = OptionalType::get(swiftParamTy);
28252826

0 commit comments

Comments
 (0)