Skip to content

Commit ad42a9f

Browse files
committed
[AST] Associated isActorSelf with VarDecl
1 parent 2c66b20 commit ad42a9f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5300,6 +5300,9 @@ class VarDecl : public AbstractStorageDecl {
53005300
/// Returns true if the name is the self identifier and is implicit.
53015301
bool isSelfParameter() const;
53025302

5303+
/// Check whether the variable is the "self" of an actor method.
5304+
bool isActorSelf() const;
5305+
53035306
/// Determine whether this property will be part of the implicit memberwise
53045307
/// initializer.
53055308
///

lib/AST/Decl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6042,6 +6042,20 @@ bool VarDecl::isSelfParameter() const {
60426042
return false;
60436043
}
60446044

6045+
bool VarDecl::isActorSelf() const {
6046+
if (!isSelfParameter() && !isSelfParamCapture())
6047+
return false;
6048+
6049+
auto *dc = getDeclContext();
6050+
while (!dc->isTypeContext() && !dc->isModuleScopeContext())
6051+
dc = dc->getParent();
6052+
6053+
// Check if this `self` parameter belogs to an actor declaration or
6054+
// extension.
6055+
auto nominal = dc->getSelfNominalTypeDecl();
6056+
return nominal && nominal->isActor();
6057+
}
6058+
60456059
/// Whether the given variable is the backing storage property for
60466060
/// a declared property that is either `lazy` or has an attached
60476061
/// property wrapper.

0 commit comments

Comments
 (0)