[Macros] "Subsume" the initializer when an accessor macros adds non-observers

When an accessor macro adds a non-observing accessor to a property, it
subsumes the initializer. We had previously modeled this as removing
the initializer, but doing so means that the initializer could not be
used for type inference and was lost in the AST.

Explicitly mark the initializer as "subsumed" here, and be more
careful when querying the initializer to distinguish between "the
initializer that was written" and "the initializer that will execute"
in more places. This distinction already existed at the
pattern-binding level, but not at the variable-declaration level.

This is the proper fix for the circular reference issue described in
rdar://108565923 (test case in the prior commit).
This commit is contained in:
Doug Gregor
2023-04-28 09:50:00 -07:00
parent 10027fbab1
commit 593c2364e8
10 changed files with 46 additions and 17 deletions

View File

@@ -184,7 +184,7 @@ private:
// Don't capture variables which aren't default-initialized.
if (auto *VD = dyn_cast<VarDecl>(DstDecl))
if (!VD->isParentInitialized() &&
if (!VD->isParentExecutabledInitialized() &&
!(isa<ParamDecl>(VD) &&
cast<ParamDecl>(VD)->isInOut()))
return Action::Continue(OriginalExpr);