@@ -1509,31 +1509,14 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1509
1509
Closures.push_back (ACE);
1510
1510
}
1511
1511
1512
- static bool isEnclosingSelfReference (VarDecl *var,
1513
- const AbstractClosureExpr *inClosure) {
1514
- if (var->isSelfParameter ())
1515
- return true ;
1516
-
1517
- // Capture variables have a DC of the parent function.
1518
- if (inClosure && var->isSelfParamCapture () &&
1519
- var->getDeclContext () != inClosure->getParent ())
1520
- return true ;
1521
-
1522
- return false ;
1523
- }
1524
-
1525
1512
// / Return true if this is an implicit reference to self which is required
1526
1513
// / to be explicit in an escaping closure. Metatype references and value
1527
1514
// / type references are excluded.
1528
- static bool isImplicitSelfParamUseLikelyToCauseCycle (Expr *E,
1529
- const AbstractClosureExpr *inClosure) {
1515
+ static bool isImplicitSelfParamUseLikelyToCauseCycle (Expr *E) {
1530
1516
auto *DRE = dyn_cast<DeclRefExpr>(E);
1531
1517
1532
- if (!DRE || !DRE->isImplicit ())
1533
- return false ;
1534
-
1535
- auto var = dyn_cast<VarDecl>(DRE->getDecl ());
1536
- if (!var || !isEnclosingSelfReference (var, inClosure))
1518
+ if (!DRE || !DRE->isImplicit () || !isa<VarDecl>(DRE->getDecl ()) ||
1519
+ !cast<VarDecl>(DRE->getDecl ())->isSelfParameter ())
1537
1520
return false ;
1538
1521
1539
1522
// Defensive check for type. If the expression doesn't have type here, it
@@ -1616,7 +1599,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1616
1599
1617
1600
SourceLoc memberLoc = SourceLoc ();
1618
1601
if (auto *MRE = dyn_cast<MemberRefExpr>(E))
1619
- if (isImplicitSelfParamUseLikelyToCauseCycle (MRE->getBase (), ACE )) {
1602
+ if (isImplicitSelfParamUseLikelyToCauseCycle (MRE->getBase ())) {
1620
1603
auto baseName = MRE->getMember ().getDecl ()->getBaseName ();
1621
1604
memberLoc = MRE->getLoc ();
1622
1605
Diags.diagnose (memberLoc,
@@ -1626,7 +1609,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1626
1609
1627
1610
// Handle method calls with a specific diagnostic + fixit.
1628
1611
if (auto *DSCE = dyn_cast<DotSyntaxCallExpr>(E))
1629
- if (isImplicitSelfParamUseLikelyToCauseCycle (DSCE->getBase (), ACE ) &&
1612
+ if (isImplicitSelfParamUseLikelyToCauseCycle (DSCE->getBase ()) &&
1630
1613
isa<DeclRefExpr>(DSCE->getFn ())) {
1631
1614
auto MethodExpr = cast<DeclRefExpr>(DSCE->getFn ());
1632
1615
memberLoc = DSCE->getLoc ();
@@ -1641,7 +1624,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
1641
1624
}
1642
1625
1643
1626
// Catch any other implicit uses of self with a generic diagnostic.
1644
- if (isImplicitSelfParamUseLikelyToCauseCycle (E, ACE ))
1627
+ if (isImplicitSelfParamUseLikelyToCauseCycle (E))
1645
1628
Diags.diagnose (E->getLoc (), diag::implicit_use_of_self_in_closure);
1646
1629
1647
1630
return { true , E };
0 commit comments