mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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();
|
||||
}
|
||||
|
||||
25
test/ClangImporter/rdar102564592.swift
Normal file
25
test/ClangImporter/rdar102564592.swift
Normal 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user