@@ -1745,7 +1745,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1745
1745
ASTContext &ctx = inClosure->getASTContext ();
1746
1746
1747
1747
auto requiresSelfQualification =
1748
- isClosureRequiringSelfQualification (inClosure, ctx );
1748
+ isClosureRequiringSelfQualification (inClosure);
1749
1749
1750
1750
// Metatype self captures don't extend the lifetime of an object.
1751
1751
if (captureType->is <MetatypeType>()) {
@@ -1783,7 +1783,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1783
1783
// that defines self if present.
1784
1784
if (validateSelfRebindings) {
1785
1785
if (auto conditionalStmt = parentConditionalStmt (selfDecl)) {
1786
- if (!hasValidSelfRebinding (conditionalStmt, inClosure )) {
1786
+ if (!hasValidSelfRebinding (conditionalStmt, ctx )) {
1787
1787
return false ;
1788
1788
}
1789
1789
}
@@ -1793,7 +1793,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1793
1793
// closure unwraps self. If not, implicit self is not allowed
1794
1794
// in this closure or in any nested closure.
1795
1795
if (closureHasWeakSelfCapture (inClosure) &&
1796
- !hasValidSelfRebinding (parentConditionalStmt (selfDecl), inClosure )) {
1796
+ !hasValidSelfRebinding (parentConditionalStmt (selfDecl), ctx )) {
1797
1797
return false ;
1798
1798
}
1799
1799
@@ -1967,7 +1967,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1967
1967
1968
1968
static bool
1969
1969
hasValidSelfRebinding (const LabeledConditionalStmt *conditionalStmt,
1970
- const AbstractClosureExpr *inClosure ) {
1970
+ ASTContext &ctx ) {
1971
1971
if (!conditionalStmt) {
1972
1972
return false ;
1973
1973
}
@@ -1980,8 +1980,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1980
1980
// guard let self = self else { return }
1981
1981
// method() // <- implicit self is not allowed
1982
1982
//
1983
- return conditionalStmt->rebindsSelf (inClosure->getASTContext (),
1984
- /* requiresCaptureListRef*/ true );
1983
+ return conditionalStmt->rebindsSelf (ctx, /* requiresCaptureListRef*/ true );
1985
1984
}
1986
1985
1987
1986
// / The `LabeledConditionalStmt` that contains the given `ValueDecl` if
@@ -2064,8 +2063,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2064
2063
// / Return true if this is a closure expression that will require explicit
2065
2064
// / use or capture of "self." for qualification of member references.
2066
2065
static bool
2067
- isClosureRequiringSelfQualification (const AbstractClosureExpr *CE,
2068
- ASTContext &Ctx) {
2066
+ isClosureRequiringSelfQualification (const AbstractClosureExpr *CE) {
2069
2067
if (closureHasWeakSelfCapture (CE)) {
2070
2068
return true ;
2071
2069
}
@@ -2245,7 +2243,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2245
2243
// to use implicit self, even after fixing any invalid parents.
2246
2244
auto isEscapingAutoclosure =
2247
2245
isa<AutoClosureExpr>(ACE) &&
2248
- isClosureRequiringSelfQualification (ACE, Ctx );
2246
+ isClosureRequiringSelfQualification (ACE);
2249
2247
if (!isEscapingAutoclosure) {
2250
2248
closureForDiagnostics = parentDisallowingImplicitSelf;
2251
2249
}
@@ -2382,7 +2380,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2382
2380
return true ;
2383
2381
}
2384
2382
2385
- if (isUsageAlwaysPreviouslyRejected (selfDecl, ACE )) {
2383
+ if (isUsageAlwaysPreviouslyRejected (selfDecl)) {
2386
2384
return false ;
2387
2385
}
2388
2386
@@ -2429,7 +2427,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2429
2427
}
2430
2428
2431
2429
if (auto condStmt = parentConditionalStmt (selfDecl)) {
2432
- auto isValidSelfRebinding = hasValidSelfRebinding (condStmt, ACE );
2430
+ auto isValidSelfRebinding = hasValidSelfRebinding (condStmt, Ctx );
2433
2431
2434
2432
// Swfit 5.8 permitted implicit self without validating any
2435
2433
// parent closures. If implicit self is only disallowed due to
@@ -2443,8 +2441,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2443
2441
// If the binding is valid when only checking for a load expr,
2444
2442
// then we must only warn.
2445
2443
auto usesLoadExpr =
2446
- condStmt->rebindsSelf (ACE->getASTContext (),
2447
- /* requiresCaptureListRef*/ false ,
2444
+ condStmt->rebindsSelf (Ctx, /* requiresCaptureListRef*/ false ,
2448
2445
/* requireLoadExpr*/ true );
2449
2446
2450
2447
if (!isValidSelfRebinding && usesLoadExpr) {
@@ -2457,12 +2454,11 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2457
2454
2458
2455
// / Checks if this implicit self usage was always previously rejected as
2459
2456
// / invalid, so can continue to be treated an error.
2460
- bool isUsageAlwaysPreviouslyRejected (ValueDecl *selfDecl,
2461
- AbstractClosureExpr *ACE) {
2457
+ bool isUsageAlwaysPreviouslyRejected (ValueDecl *selfDecl) {
2462
2458
// If the self decl refers to a weak self unwrap condition
2463
2459
// in some parent closure, then there is no source-compatibility
2464
2460
// requirement to avoid an error.
2465
- return hasValidSelfRebinding (parentConditionalStmt (selfDecl), ACE );
2461
+ return hasValidSelfRebinding (parentConditionalStmt (selfDecl), Ctx );
2466
2462
}
2467
2463
2468
2464
// / Checks if this is a usage of implicit self in a strong self closure
@@ -2499,7 +2495,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2499
2495
if (DC->isLocalContext ()) {
2500
2496
while (DC->getParent ()->isLocalContext () && !ACE) {
2501
2497
if (auto *closure = dyn_cast<AbstractClosureExpr>(DC))
2502
- if (DiagnoseWalker::isClosureRequiringSelfQualification (closure, ctx ))
2498
+ if (DiagnoseWalker::isClosureRequiringSelfQualification (closure))
2503
2499
ACE = const_cast <AbstractClosureExpr *>(closure);
2504
2500
DC = DC->getParent ();
2505
2501
}
0 commit comments