Skip to content

Commit 07aedc4

Browse files
Copy all the options when cloning subscript accessor
1 parent 700800c commit 07aedc4

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7000,6 +7000,10 @@ class ParamDecl : public VarDecl {
70007000
/// Create a an identical copy of this ParamDecl.
70017001
static ParamDecl *clone(const ASTContext &Ctx, ParamDecl *PD);
70027002

7003+
static ParamDecl *cloneAccessor(const ASTContext &Ctx,
7004+
ParamDecl const *subscriptParam,
7005+
DeclContext *Parent);
7006+
70037007
static ParamDecl *
70047008
createImplicit(ASTContext &Context, SourceLoc specifierLoc,
70057009
SourceLoc argumentNameLoc, Identifier argumentName,

lib/AST/Decl.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8918,6 +8918,21 @@ ParamDecl *ParamDecl::clone(const ASTContext &Ctx, ParamDecl *PD) {
89188918
return Clone;
89198919
}
89208920

8921+
ParamDecl *ParamDecl::cloneAccessor(const ASTContext &Ctx,
8922+
ParamDecl const *subscriptParam,
8923+
DeclContext *Parent) {
8924+
auto *param = new (Ctx) ParamDecl(
8925+
subscriptParam->getSpecifierLoc(), subscriptParam->getArgumentNameLoc(),
8926+
subscriptParam->getArgumentName(), subscriptParam->getNameLoc(),
8927+
subscriptParam->getName(), /*declContext*/ Parent);
8928+
param->setOptions(subscriptParam->getOptions());
8929+
8930+
// The cloned parameter is implicit.
8931+
param->setImplicit();
8932+
8933+
return param;
8934+
}
8935+
89218936
ParamDecl *
89228937
ParamDecl::createImplicit(ASTContext &Context, SourceLoc specifierLoc,
89238938
SourceLoc argumentNameLoc, Identifier argumentName,
@@ -11128,23 +11143,7 @@ AccessorDecl *AccessorDecl::createParsed(
1112811143
paramsEnd = indices->getEndLoc();
1112911144
}
1113011145
for (auto *subscriptParam : *indices) {
11131-
// Clone the parameter.
11132-
auto *param = new (ctx) ParamDecl(
11133-
subscriptParam->getSpecifierLoc(),
11134-
subscriptParam->getArgumentNameLoc(),
11135-
subscriptParam->getArgumentName(), subscriptParam->getNameLoc(),
11136-
subscriptParam->getName(), /*declContext*/ accessor);
11137-
11138-
// The cloned parameter is implicit.
11139-
param->setImplicit();
11140-
11141-
// TODO: Check why IsVariadic is not copied.
11142-
param->setAutoClosure(subscriptParam->isAutoClosure());
11143-
param->setIsolated(subscriptParam->isIsolated());
11144-
// TODO: Check why IsAddressable is not copied.
11145-
param->setSending(subscriptParam->isSending());
11146-
param->setCallerIsolated(subscriptParam->isCallerIsolated());
11147-
11146+
auto param = ParamDecl::cloneAccessor(ctx, subscriptParam, accessor);
1114811147
newParams.push_back(param);
1114911148
}
1115011149

0 commit comments

Comments
 (0)