Skip to content

Commit ac3866a

Browse files
committed
[cxx-interop][symbolic interface] add a fallback for unknown generic type to be Any
1 parent aa397c7 commit ac3866a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,6 +2179,10 @@ findGenericTypeInGenericDecls(ClangImporter::Implementation &impl,
21792179
llvm::find_if(genericParams, [name](GenericTypeParamDecl *generic) {
21802180
return generic->getName().str() == name;
21812181
});
2182+
// We sometimes are unable compute the exact Swift type
2183+
// of symbolic declarations. Fallback to using `Any` in that case.
2184+
if (impl.importSymbolicCXXDecls && genericParamIter == genericParams.end())
2185+
return impl.SwiftContext.TheAnyType;
21822186
// TODO: once we support generics in class types, replace this with
21832187
// "return nullptr". Once support for template classes, this will need to
21842188
// be updated, though. I'm leaving the assert here to make it easier to

test/Interop/Cxx/symbolic-imports/print-symbolic-module-interface.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ namespace ns {
4545

4646
using MyType = ns::TemplateRecord<int>;
4747

48+
template<class X>
49+
class OuterTemp2 {
50+
public:
51+
template<class T, class G>
52+
class InnerTemp2 {
53+
public:
54+
void testMe(const T& p, const X& x);
55+
56+
X x2;
57+
58+
using Y = X;
59+
};
60+
};
61+
4862
// CHECK: enum ns {
4963
// CHECK-NEXT: struct B {
5064
// CHECK-NEXT: init()
@@ -64,3 +78,11 @@ using MyType = ns::TemplateRecord<int>;
6478
// CHECK-NEXT: static func freeFunction(_ x: Int32, _ y: Int32) -> Int32
6579
// CHECK-NEXT: }
6680
// CHECK-NEXT: typealias MyType = ns.TemplateRecord
81+
// CHECK-NEXT: struct OuterTemp2 {
82+
// CHECK-NEXT: struct InnerTemp2 {
83+
// CHECK-NEXT: init(x2: Any)
84+
// CHECK-NEXT: mutating func testMe(_ p: Any, _ x: Any)
85+
// CHECK-NEXT: var x2: Any
86+
// CHECK-NEXT: typealias Y = Any
87+
// CHECK-NEXT: }
88+
// CHECK-NEXT: }

0 commit comments

Comments
 (0)