Skip to content

Commit f6b42d4

Browse files
committed
[cxx-interop] Allow imported subscript to have generic parameters.
1 parent 56e0661 commit f6b42d4

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6865,7 +6865,9 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
68656865
SourceLoc SubscriptLoc,
68666866
ParameterList *Indices,
68676867
SourceLoc ArrowLoc, Type ElementTy,
6868-
DeclContext *Parent, ClangNode ClangN);
6868+
DeclContext *Parent,
6869+
GenericParamList *GenericParams,
6870+
ClangNode ClangN);
68696871

68706872
/// \returns the way 'static'/'class' was spelled in the source.
68716873
StaticSpellingKind getStaticSpelling() const {

lib/AST/ASTVerifier.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,17 +2644,12 @@ class Verifier : public ASTWalker {
26442644
abort();
26452645
}
26462646

2647-
// FIXME: Workaround for invalid AST for imported C++ templates.
2648-
if (!var->hasClangNode()) {
2649-
// If we are performing pack iteration, variables have to carry the
2650-
// generic environment. Catching the missing environment here will prevent
2651-
// the code from being lowered.
2652-
if (var->getTypeInContext()->is<ErrorType>()) {
2653-
Out << "VarDecl is missing a Generic Environment: ";
2654-
var->getInterfaceType().print(Out);
2655-
Out << "\n";
2656-
abort();
2657-
}
2647+
// Catch cases where there's a missing generic environment.
2648+
if (var->getTypeInContext()->is<ErrorType>()) {
2649+
Out << "VarDecl is missing a Generic Environment: ";
2650+
var->getInterfaceType().print(Out);
2651+
Out << "\n";
2652+
abort();
26582653
}
26592654

26602655
// The fact that this is *directly* be a reference storage type

lib/AST/Decl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8831,6 +8831,7 @@ SubscriptDecl *SubscriptDecl::createImported(ASTContext &Context, DeclName Name,
88318831
ParameterList *Indices,
88328832
SourceLoc ArrowLoc, Type ElementTy,
88338833
DeclContext *Parent,
8834+
GenericParamList *GenericParams,
88348835
ClangNode ClangN) {
88358836
assert(ClangN && ElementTy);
88368837
auto *DeclPtr = allocateMemoryForDecl<SubscriptDecl>(
@@ -8839,7 +8840,7 @@ SubscriptDecl *SubscriptDecl::createImported(ASTContext &Context, DeclName Name,
88398840
auto *const SD = ::new (DeclPtr)
88408841
SubscriptDecl(Name, SourceLoc(), StaticSpellingKind::None, SubscriptLoc,
88418842
Indices, ArrowLoc, /*ElementTyR=*/nullptr, Parent,
8842-
/*GenericParams=*/nullptr);
8843+
GenericParams);
88438844
SD->setElementInterfaceType(ElementTy);
88448845
SD->setClangNode(ClangN);
88458846
return SD;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7151,6 +7151,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
71517151
name, decl->getLoc(),
71527152
bodyParams, decl->getLoc(),
71537153
elementTy, dc,
7154+
/*genericParams=*/nullptr,
71547155
getter->getClangNode());
71557156

71567157
bool IsObjCDirect = false;

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,8 @@ SubscriptDecl *SwiftDeclSynthesizer::makeSubscript(FuncDecl *getter,
16831683

16841684
SubscriptDecl *subscript = SubscriptDecl::createImported(
16851685
ctx, name, getterImpl->getLoc(), bodyParams, getterImpl->getLoc(),
1686-
elementTy, dc, getterImpl->getClangNode());
1686+
elementTy, dc, getterImpl->getGenericParams(),
1687+
getterImpl->getClangNode());
16871688
subscript->setAccess(AccessLevel::Public);
16881689

16891690
AccessorDecl *getterDecl = AccessorDecl::create(

0 commit comments

Comments
 (0)