Skip to content

Commit 22280de

Browse files
Copy all the options when cloning subscript accessor
1 parent 5376e56 commit 22280de

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
@@ -6993,6 +6993,10 @@ class ParamDecl : public VarDecl {
69936993
/// Create a an identical copy of this ParamDecl.
69946994
static ParamDecl *clone(const ASTContext &Ctx, ParamDecl *PD);
69956995

6996+
static ParamDecl *cloneAccessor(const ASTContext &Ctx,
6997+
ParamDecl const *subscriptParam,
6998+
DeclContext *Parent);
6999+
69967000
static ParamDecl *
69977001
createImplicit(ASTContext &Context, SourceLoc specifierLoc,
69987002
SourceLoc argumentNameLoc, Identifier argumentName,

lib/AST/Decl.cpp

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

8891+
ParamDecl *ParamDecl::cloneAccessor(const ASTContext &Ctx,
8892+
ParamDecl const *subscriptParam,
8893+
DeclContext *Parent) {
8894+
auto *param = new (Ctx) ParamDecl(
8895+
subscriptParam->getSpecifierLoc(), subscriptParam->getArgumentNameLoc(),
8896+
subscriptParam->getArgumentName(), subscriptParam->getNameLoc(),
8897+
subscriptParam->getName(), /*declContext*/ Parent);
8898+
param->setOptions(subscriptParam->getOptions());
8899+
8900+
// The cloned parameter is implicit.
8901+
param->setImplicit();
8902+
8903+
return param;
8904+
}
8905+
88918906
ParamDecl *
88928907
ParamDecl::createImplicit(ASTContext &Context, SourceLoc specifierLoc,
88938908
SourceLoc argumentNameLoc, Identifier argumentName,
@@ -11107,23 +11122,7 @@ AccessorDecl *AccessorDecl::createParsed(
1110711122
paramsEnd = indices->getEndLoc();
1110811123
}
1110911124
for (auto *subscriptParam : *indices) {
11110-
// Clone the parameter.
11111-
auto *param = new (ctx) ParamDecl(
11112-
subscriptParam->getSpecifierLoc(),
11113-
subscriptParam->getArgumentNameLoc(),
11114-
subscriptParam->getArgumentName(), subscriptParam->getNameLoc(),
11115-
subscriptParam->getName(), /*declContext*/ accessor);
11116-
11117-
// The cloned parameter is implicit.
11118-
param->setImplicit();
11119-
11120-
// TODO: Check why IsVariadic is not copied.
11121-
param->setAutoClosure(subscriptParam->isAutoClosure());
11122-
param->setIsolated(subscriptParam->isIsolated());
11123-
// TODO: Check why IsAddressable is not copied.
11124-
param->setSending(subscriptParam->isSending());
11125-
param->setCallerIsolated(subscriptParam->isCallerIsolated());
11126-
11125+
auto param = ParamDecl::cloneAccessor(ctx, subscriptParam, accessor);
1112711126
newParams.push_back(param);
1112811127
}
1112911128

0 commit comments

Comments
 (0)