[ClangImporter] Correctly set parent type when importing ObjC pointers

Fixes an issue where parent type wasn't set for qualified ObjC
pointers which leads to crashes during Sema because non-pointer
uses are imported correctly.

Resolves: rdar://102564592
This commit is contained in:
Pavel Yaskevich
2024-11-19 11:15:22 -08:00
parent 26e888e45e
commit f4595923ba
2 changed files with 36 additions and 1 deletions

View File

@@ -1059,6 +1059,16 @@ namespace {
// If the objc type has any generic args, convert them and bind them to
// the imported class type.
if (imported->getGenericParams()) {
auto *dc = imported->getDeclContext();
Type parentTy;
// Check if this is a nested type and if so,
// fetch the parent type.
if (dc->isTypeContext()) {
parentTy = dc->getDeclaredInterfaceType();
if (parentTy->is<ErrorType>())
return Type();
}
unsigned typeParamCount = imported->getGenericParams()->size();
auto typeArgs = type->getObjectType()->getTypeArgs();
assert(typeArgs.empty() || typeArgs.size() == typeParamCount);
@@ -1084,7 +1094,7 @@ namespace {
}
assert(importedTypeArgs.size() == typeParamCount);
importedType = BoundGenericClassType::get(
imported, nullptr, importedTypeArgs);
imported, parentTy, importedTypeArgs);
} else {
importedType = imported->getDeclaredInterfaceType();
}

View File

@@ -0,0 +1,25 @@
// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src
// RUN: %target-swift-frontend -typecheck -disable-objc-attr-requires-foundation-module -import-objc-header %t/src/ObjC.h -O %t/src/main.swift
// REQUIRES: objc_interop
//--- ObjC.h
@interface MyUnit
@end
__attribute__((swift_name("Metrics.SomeMetric")))
@interface SomeMetric <T: MyUnit *>
@end
@interface Metrics
@property (readonly, strong) SomeMetric<MyUnit *> *metric;
@end
//--- main.swift
func test(metrics: Metrics) -> Metrics.SomeMetric<MyUnit> {
metrics.metric
}