@@ -2004,40 +2004,6 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
20042004 diag.fixItInsertAfter (closureExpr->getLoc (), " [self] in" + trailing);
20052005 }
20062006 };
2007-
2008- // A walker that verifies whether or not `exprToMatch`
2009- // is a descendent of the AST node being walked
2010- class ExprIsDescendantWalker : public BaseDiagnosticWalker {
2011- Expr *exprToMatch;
2012- public:
2013- bool exprIsDescendant = false ;
2014-
2015- explicit ExprIsDescendantWalker (Expr *exprToMatch)
2016- : exprToMatch(exprToMatch) { }
2017-
2018- bool shouldWalkIntoSeparatelyCheckedClosure (ClosureExpr *expr) override {
2019- return true ;
2020- }
2021-
2022- PreWalkResult<Expr *> walkToExprPre (Expr *E) override {
2023- if (E == exprToMatch) {
2024- exprIsDescendant = true ;
2025- return Action::Stop ();
2026- }
2027-
2028- return Action::Continue (E);
2029- }
2030-
2031- PreWalkResult<Stmt *> walkToStmtPre (Stmt *S) override {
2032- // We need to look at all AST nodes, so make sure to check the children of statements
2033- return Action::Continue (S);
2034- }
2035-
2036- PreWalkAction walkToDeclPre (Decl *D) override {
2037- // We need to look at all AST nodes, so make sure to check the children of decls
2038- return Action::Continue ();
2039- }
2040- };
20412007
20422008 auto &ctx = DC->getASTContext ();
20432009 AbstractClosureExpr *ACE = nullptr ;
@@ -2050,17 +2016,6 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
20502016 }
20512017 }
20522018
2053- // Verify E is actually a descendant of ACE before we use it.
2054- // Otherwise we'd be diagnosing E within the context of a closure
2055- // that it isn't actually a part of.
2056- if (ACE) {
2057- auto isDescendantWalker = ExprIsDescendantWalker (const_cast <Expr *>(E));
2058- ACE->walk (isDescendantWalker);
2059- if (!isDescendantWalker.exprIsDescendant ) {
2060- ACE = nullptr ;
2061- }
2062- }
2063-
20642019 const_cast <Expr *>(E)->walk (DiagnoseWalker (ctx, ACE));
20652020}
20662021
0 commit comments