@@ -1681,21 +1681,12 @@ static void diagRecursivePropertyAccess(const Expr *E, const DeclContext *DC) {
16811681}
16821682
16831683// / The `weak self` capture of this closure if present
1684- static VarDecl *selfCapture (const AbstractClosureExpr *ACE) {
1684+ static VarDecl *weakSelfCapture (const AbstractClosureExpr *ACE) {
16851685 if (auto closureExpr = dyn_cast<ClosureExpr>(ACE)) {
16861686 if (auto selfDecl = closureExpr->getCapturedSelfDecl ()) {
1687- return selfDecl;
1688- }
1689- }
1690-
1691- return nullptr ;
1692- }
1693-
1694- // / The `weak self` capture of this closure if present
1695- static VarDecl *weakSelfCapture (const AbstractClosureExpr *ACE) {
1696- if (auto selfDecl = selfCapture (ACE)) {
1697- if (selfDecl->getInterfaceType ()->is <WeakStorageType>()) {
1698- return selfDecl;
1687+ if (selfDecl->getInterfaceType ()->is <WeakStorageType>()) {
1688+ return selfDecl;
1689+ }
16991690 }
17001691 }
17011692
@@ -1890,13 +1881,15 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
18901881 }
18911882 }
18921883
1893- // If the self decl refers to a `guard let self` / `if let self` conditon,
1894- // we need to validate it.
1895- auto selfDeclDefinedInConditionalStmt = false ;
1896- auto isInvalidSelfDeclRebinding = false ;
1897- if (auto condStmt = parentConditionalStmt (selfDecl)) {
1898- selfDeclDefinedInConditionalStmt = true ;
1899- isInvalidSelfDeclRebinding = !hasValidSelfRebinding (condStmt, ctx);
1884+ // If the self decl refers to a weak capture, then implicit self is not
1885+ // allowed. Self must me unwrapped in a weak self closure.
1886+ // - When validating implicit self usage in a nested closure, it's not
1887+ // necessary for self to be unwrapped in this parent closure. If self
1888+ // isn't unwrapped correctly in the nested closure, we would have
1889+ // already noticed when validating that closure.
1890+ if (selfDecl->getInterfaceType ()->is <WeakStorageType>() &&
1891+ !isValidatingParentClosures) {
1892+ return false ;
19001893 }
19011894
19021895 // If the self decl refers to an invalid unwrapping conditon like
@@ -1906,26 +1899,10 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
19061899 // be a closure nested in some parent closure with a `weak self`
19071900 // capture, so we should always validate the conditional statement
19081901 // that defines self if present.
1909- if (isInvalidSelfDeclRebinding) {
1910- return false ;
1911- }
1912-
1913- // Within a closure with a `[weak self]` capture, implicit self is only
1914- // allowed if self has been unwrapped in a previous conditional statement.
1915- // - When validating implicit self usage in a nested closure, it's not
1916- // necessary for self to be unwrapped in this parent closure. If self
1917- // isn't unwrapped correctly in the nested closure, we would have
1918- // already noticed when validating that closure.
1919- if (closureHasWeakSelfCapture (inClosure) &&
1920- !selfDeclDefinedInConditionalStmt && !isValidatingParentClosures) {
1921- return false ;
1922- }
1923-
1924- // If the self decl refers to a weak capture in a parent closure,
1925- // then implicit self is not allowed.
1926- if (selfDecl->getInterfaceType ()->is <WeakStorageType>() &&
1927- !closureHasWeakSelfCapture (inClosure)) {
1928- return false ;
1902+ if (auto condStmt = parentConditionalStmt (selfDecl)) {
1903+ if (!hasValidSelfRebinding (condStmt, ctx)) {
1904+ return false ;
1905+ }
19291906 }
19301907
19311908 if (auto autoclosure = dyn_cast<AutoClosureExpr>(inClosure)) {
0 commit comments