Skip to content

Commit e4436ba

Browse files
authored
Merge pull request #70348 from hborla/cxx-generic-subscript
[cxx-interop] Allow imported subscript to have generic parameters.
2 parents 443cac2 + 450e59c commit e4436ba

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6859,7 +6859,9 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
68596859
SourceLoc SubscriptLoc,
68606860
ParameterList *Indices,
68616861
SourceLoc ArrowLoc, Type ElementTy,
6862-
DeclContext *Parent, ClangNode ClangN);
6862+
DeclContext *Parent,
6863+
GenericParamList *GenericParams,
6864+
ClangNode ClangN);
68636865

68646866
/// \returns the way 'static'/'class' was spelled in the source.
68656867
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
@@ -7148,6 +7148,7 @@ SwiftDeclConverter::importSubscript(Decl *decl,
71487148
name, decl->getLoc(),
71497149
bodyParams, decl->getLoc(),
71507150
elementTy, dc,
7151+
/*genericParams=*/nullptr,
71517152
getter->getClangNode());
71527153

71537154
bool IsObjCDirect = false;

lib/ClangImporter/SwiftDeclSynthesizer.cpp

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

16771677
SubscriptDecl *subscript = SubscriptDecl::createImported(
16781678
ctx, name, getterImpl->getLoc(), bodyParams, getterImpl->getLoc(),
1679-
elementTy, dc, getterImpl->getClangNode());
1679+
elementTy, dc, getterImpl->getGenericParams(),
1680+
getterImpl->getClangNode());
16801681
subscript->setAccess(AccessLevel::Public);
16811682

16821683
AccessorDecl *getterDecl =

test/Interop/Cxx/operators/member-inline-module-interface.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
// CHECK-NEXT: }
152152

153153
// CHECK: struct TemplatedOperatorArrayByVal {
154-
// CHECK: subscript(i: T) -> T { mutating get }
154+
// CHECK: subscript<T>(i: T) -> T { mutating get }
155155
// CHECK: @available(*, unavailable, message: "use subscript")
156156
// CHECK: mutating func __operatorSubscriptConst<T>(_ i: T) -> T
157157
// CHECK-NOT: mutating func __operatorPlus<T>(_ i: T) -> UnsafeMutablePointer<T>

0 commit comments

Comments
 (0)