Skip to content

Commit 0f28563

Browse files
committed
[CS] Invalidate auxiliary vars in markInvalid
And make sure we mark any PatternBindingDecl initializers as having been checked to avoid re-checking. This fixes a crash where we could attempt to re-check a property wrapper to compute its backing type.
1 parent 885f9ba commit 0f28563

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lib/Sema/SyntacticElementTarget.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,29 @@ void SyntacticElementTarget::markInvalid() const {
306306
return Action::Continue(P);
307307
}
308308

309+
void invalidateVarDecl(VarDecl *VD) {
310+
// Only set invalid if we don't already have an interface type computed.
311+
if (!VD->hasInterfaceType())
312+
VD->setInvalid();
313+
314+
// Also do the same for any auxiliary vars.
315+
VD->visitAuxiliaryVars(/*forNameLookup*/ false, [&](VarDecl *VD) {
316+
invalidateVarDecl(VD);
317+
});
318+
}
319+
309320
PreWalkAction walkToDeclPre(Decl *D) override {
310321
// Mark any VarDecls and PatternBindingDecls as invalid.
311322
if (auto *VD = dyn_cast<VarDecl>(D)) {
312-
// Only set invalid if we don't already have an interface type computed.
313-
if (!VD->hasInterfaceType())
314-
D->setInvalid();
315-
} else if (isa<PatternBindingDecl>(D)) {
316-
D->setInvalid();
323+
invalidateVarDecl(VD);
324+
} else if (auto *PBD = dyn_cast<PatternBindingDecl>(D)) {
325+
PBD->setInvalid();
326+
// Make sure we mark the initializers as having been checked, otherwise
327+
// `typeCheckPatternBinding` might try to check them again.
328+
for (auto i : range(0, PBD->getNumPatternEntries())) {
329+
if (PBD->isInitialized(i))
330+
PBD->setInitializerChecked(i);
331+
}
317332
}
318333
return Action::VisitNodeIf(isa<PatternBindingDecl>(D));
319334
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// {"kind":"typecheck","signature":"swift::constraints::ConstraintSystem::getClosureType(swift::ClosureExpr const*) const","signatureAssert":"Assertion failed: (result), function getClosureType"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
@propertyWrapper struct a {
4+
}
5+
{
6+
@a var x =
7+
if <#expression#> {
8+
return
9+
}
10+
_x
11+
}

0 commit comments

Comments
 (0)