Skip to content

[cxx-interop][symbolic interface] add a fallback for unknown generic … #67728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2179,6 +2179,10 @@ findGenericTypeInGenericDecls(ClangImporter::Implementation &impl,
llvm::find_if(genericParams, [name](GenericTypeParamDecl *generic) {
return generic->getName().str() == name;
});
// We sometimes are unable compute the exact Swift type
// of symbolic declarations. Fallback to using `Any` in that case.
if (impl.importSymbolicCXXDecls && genericParamIter == genericParams.end())
return impl.SwiftContext.TheAnyType;
// TODO: once we support generics in class types, replace this with
// "return nullptr". Once support for template classes, this will need to
// be updated, though. I'm leaving the assert here to make it easier to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ namespace ns {

using MyType = ns::TemplateRecord<int>;

template<class X>
class OuterTemp2 {
public:
template<class T, class G>
class InnerTemp2 {
public:
void testMe(const T& p, const X& x);

X x2;

using Y = X;
};
};

// CHECK: enum ns {
// CHECK-NEXT: struct B {
// CHECK-NEXT: init()
Expand All @@ -64,3 +78,11 @@ using MyType = ns::TemplateRecord<int>;
// CHECK-NEXT: static func freeFunction(_ x: Int32, _ y: Int32) -> Int32
// CHECK-NEXT: }
// CHECK-NEXT: typealias MyType = ns.TemplateRecord
// CHECK-NEXT: struct OuterTemp2 {
// CHECK-NEXT: struct InnerTemp2 {
// CHECK-NEXT: init(x2: Any)
// CHECK-NEXT: mutating func testMe(_ p: Any, _ x: Any)
// CHECK-NEXT: var x2: Any
// CHECK-NEXT: typealias Y = Any
// CHECK-NEXT: }
// CHECK-NEXT: }