@@ -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
}
@@ -2253,7 +2251,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2253
2251
// to use implicit self, even after fixing any invalid parents.
2254
2252
auto isEscapingAutoclosure =
2255
2253
isa<AutoClosureExpr>(ACE) &&
2256
- isClosureRequiringSelfQualification (ACE, Ctx );
2254
+ isClosureRequiringSelfQualification (ACE);
2257
2255
if (!isEscapingAutoclosure) {
2258
2256
closureForDiagnostics = parentDisallowingImplicitSelf;
2259
2257
}
@@ -2390,7 +2388,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2390
2388
return true ;
2391
2389
}
2392
2390
2393
- if (isUsageAlwaysPreviouslyRejected (selfDecl, ACE )) {
2391
+ if (isUsageAlwaysPreviouslyRejected (selfDecl)) {
2394
2392
return false ;
2395
2393
}
2396
2394
@@ -2436,7 +2434,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2436
2434
}
2437
2435
2438
2436
if (auto condStmt = parentConditionalStmt (selfDecl)) {
2439
- auto isValidSelfRebinding = hasValidSelfRebinding (condStmt, ACE );
2437
+ auto isValidSelfRebinding = hasValidSelfRebinding (condStmt, Ctx );
2440
2438
2441
2439
// Swfit 5.8 permitted implicit self without validating any
2442
2440
// parent closures. If implicit self is only disallowed due to
@@ -2450,8 +2448,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2450
2448
// If the binding is valid when only checking for a load expr,
2451
2449
// then we must only warn.
2452
2450
auto usesLoadExpr =
2453
- condStmt->rebindsSelf (ACE->getASTContext (),
2454
- /* requiresCaptureListRef*/ false ,
2451
+ condStmt->rebindsSelf (Ctx, /* requiresCaptureListRef*/ false ,
2455
2452
/* requireLoadExpr*/ true );
2456
2453
2457
2454
if (!isValidSelfRebinding && usesLoadExpr) {
@@ -2464,12 +2461,11 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2464
2461
2465
2462
// / Checks if this implicit self usage was always previously rejected as
2466
2463
// / invalid, so can continue to be treated an error.
2467
- bool isUsageAlwaysPreviouslyRejected (ValueDecl *selfDecl,
2468
- AbstractClosureExpr *ACE) {
2464
+ bool isUsageAlwaysPreviouslyRejected (ValueDecl *selfDecl) {
2469
2465
// If the self decl refers to a weak self unwrap condition
2470
2466
// in some parent closure, then there is no source-compatibility
2471
2467
// requirement to avoid an error.
2472
- return hasValidSelfRebinding (parentConditionalStmt (selfDecl), ACE );
2468
+ return hasValidSelfRebinding (parentConditionalStmt (selfDecl), Ctx );
2473
2469
}
2474
2470
2475
2471
// / Checks if this is a usage of implicit self in a strong self closure
@@ -2507,7 +2503,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2507
2503
// FIXME: This is happening too early, because closure->getType() isn't set.
2508
2504
if (auto *closure = dyn_cast<AbstractClosureExpr>(DC))
2509
2505
if (closure->getType ())
2510
- if (DiagnoseWalker::isClosureRequiringSelfQualification (closure, ctx ))
2506
+ if (DiagnoseWalker::isClosureRequiringSelfQualification (closure))
2511
2507
ACE = const_cast <AbstractClosureExpr *>(closure);
2512
2508
DC = DC->getParent ();
2513
2509
}
0 commit comments