Skip to content

Commit c03950b

Browse files
committed
Use LabeledConditionalStmt instead of just IfStmt / GuardStmt
1 parent 20ed27a commit c03950b

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,10 +1548,10 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
15481548

15491549
if (auto var = dyn_cast<VarDecl>(DRE->getDecl())) {
15501550
if (auto parentStmt = var->getParentPatternStmt()) {
1551-
if (isa<GuardStmt>(parentStmt) || isa<IfStmt>(parentStmt)) {
1551+
if (isa<LabeledConditionalStmt>(parentStmt)) {
15521552
// If this `self` decl was not captured explicitly by this closure,
15531553
// but is actually from an outer `weak` capture's `if let self = self`
1554-
// or `guard let self = self`, then we don't allow implicit self.
1554+
// or `guard let self = self` etc, then we don't allow implicit self.
15551555
if (!isExplicitWeakSelfCapture) {
15561556
return true;
15571557
}
@@ -1645,9 +1645,11 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
16451645
if (auto declRef = dyn_cast<DeclRefExpr>(selfRef)) {
16461646
if (auto decl = declRef->getDecl()) {
16471647
if (auto varDecl = dyn_cast<VarDecl>(decl)) {
1648-
// If the self decl was defined in an `if` or `guard` statement, we know this is an inner closure of some outer closure's `weak self` capture. Since this wasn't allowed in Swift 5.5, we should just always emit an error.
1648+
// If the self decl was defined in an conditional binding in an `if`/`guard`/`while`,
1649+
// then we know this is an inner closure of some outer closure's `weak self` capture.
1650+
// Since this wasn't allowed in Swift 5.5, we should just always emit an error.
16491651
if (auto parentStmt = varDecl->getParentPatternStmt()) {
1650-
if (isa<GuardStmt>(parentStmt) || isa<IfStmt>(parentStmt)) {
1652+
if (isa<LabeledConditionalStmt>(parentStmt)) {
16511653
return false;
16521654
}
16531655
}

0 commit comments

Comments
 (0)