Skip to content

Commit faa176f

Browse files
committed
Record and walk the semantic initializer for a custom attribute.
1 parent 7ace136 commit faa176f

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

include/swift/AST/Attr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,7 @@ class CustomAttr final : public DeclAttribute,
14281428
TypeLoc type;
14291429
Expr *arg;
14301430
PatternBindingInitializer *initContext;
1431+
Expr *semanticInit = nullptr;
14311432

14321433
unsigned hasArgLabelLocs : 1;
14331434
unsigned numArgLabels : 16;
@@ -1463,6 +1464,9 @@ class CustomAttr final : public DeclAttribute,
14631464
Expr *getArg() const { return arg; }
14641465
void setArg(Expr *newArg) { arg = newArg; }
14651466

1467+
Expr *getSemanticInit() const { return semanticInit; }
1468+
void setSemanticInit(Expr *expr) { semanticInit = expr; }
1469+
14661470
PatternBindingInitializer *getInitContext() const { return initContext; }
14671471

14681472
static bool classof(const DeclAttribute *DA) {

lib/AST/ASTWalker.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
131131
if (doIt(mutableCustomAttr->getTypeLoc()))
132132
return true;
133133

134-
if (auto arg = customAttr->getArg()) {
134+
if (auto semanticInit = customAttr->getSemanticInit()) {
135+
if (auto newSemanticInit = doIt(semanticInit))
136+
mutableCustomAttr->setSemanticInit(newSemanticInit);
137+
else
138+
return true;
139+
} else if (auto arg = customAttr->getArg()) {
135140
if (auto newArg = doIt(arg))
136141
mutableCustomAttr->setArg(newArg);
137142
else

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,6 +2557,9 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
25572557
var->getParentPatternBinding()->setInitializerSubsumed(0);
25582558
tc.Context.setSideCachedPropertyDelegateBackingPropertyType(
25592559
var, initType->mapTypeOutOfContext());
2560+
2561+
// Record the semantic initializer.
2562+
var->getAttachedPropertyDelegate()->setSemanticInit(expr);
25602563
}
25612564

25622565
initializer = expr;

0 commit comments

Comments
 (0)