Skip to content

Commit a8a8eaf

Browse files
authored
Merge pull request #77706 from xedin/rdar-102564592
[ClangImporter] Correctly set parent type when importing ObjC pointers
2 parents 1ab968d + f459592 commit a8a8eaf

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,16 @@ namespace {
10591059
// If the objc type has any generic args, convert them and bind them to
10601060
// the imported class type.
10611061
if (imported->getGenericParams()) {
1062+
auto *dc = imported->getDeclContext();
1063+
Type parentTy;
1064+
// Check if this is a nested type and if so,
1065+
// fetch the parent type.
1066+
if (dc->isTypeContext()) {
1067+
parentTy = dc->getDeclaredInterfaceType();
1068+
if (parentTy->is<ErrorType>())
1069+
return Type();
1070+
}
1071+
10621072
unsigned typeParamCount = imported->getGenericParams()->size();
10631073
auto typeArgs = type->getObjectType()->getTypeArgs();
10641074
assert(typeArgs.empty() || typeArgs.size() == typeParamCount);
@@ -1084,7 +1094,7 @@ namespace {
10841094
}
10851095
assert(importedTypeArgs.size() == typeParamCount);
10861096
importedType = BoundGenericClassType::get(
1087-
imported, nullptr, importedTypeArgs);
1097+
imported, parentTy, importedTypeArgs);
10881098
} else {
10891099
importedType = imported->getDeclaredInterfaceType();
10901100
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %empty-directory(%t/src)
2+
// RUN: split-file %s %t/src
3+
4+
// RUN: %target-swift-frontend -typecheck -disable-objc-attr-requires-foundation-module -import-objc-header %t/src/ObjC.h -O %t/src/main.swift
5+
6+
// REQUIRES: objc_interop
7+
8+
//--- ObjC.h
9+
10+
@interface MyUnit
11+
@end
12+
13+
__attribute__((swift_name("Metrics.SomeMetric")))
14+
@interface SomeMetric <T: MyUnit *>
15+
@end
16+
17+
@interface Metrics
18+
@property (readonly, strong) SomeMetric<MyUnit *> *metric;
19+
@end
20+
21+
//--- main.swift
22+
func test(metrics: Metrics) -> Metrics.SomeMetric<MyUnit> {
23+
metrics.metric
24+
}
25+

0 commit comments

Comments
 (0)