@@ -1681,21 +1681,12 @@ static void diagRecursivePropertyAccess(const Expr *E, const DeclContext *DC) {
1681
1681
}
1682
1682
1683
1683
// / The `weak self` capture of this closure if present
1684
- static VarDecl *selfCapture (const AbstractClosureExpr *ACE) {
1684
+ static VarDecl *weakSelfCapture (const AbstractClosureExpr *ACE) {
1685
1685
if (auto closureExpr = dyn_cast<ClosureExpr>(ACE)) {
1686
1686
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
+ }
1699
1690
}
1700
1691
}
1701
1692
@@ -1890,13 +1881,15 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
1890
1881
}
1891
1882
}
1892
1883
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 ;
1900
1893
}
1901
1894
1902
1895
// If the self decl refers to an invalid unwrapping conditon like
@@ -1906,26 +1899,10 @@ class ImplicitSelfUsageChecker : public BaseDiagnosticWalker {
1906
1899
// be a closure nested in some parent closure with a `weak self`
1907
1900
// capture, so we should always validate the conditional statement
1908
1901
// 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
+ }
1929
1906
}
1930
1907
1931
1908
if (auto autoclosure = dyn_cast<AutoClosureExpr>(inClosure)) {
0 commit comments