@@ -2004,40 +2004,6 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2004
2004
diag.fixItInsertAfter (closureExpr->getLoc (), " [self] in" + trailing);
2005
2005
}
2006
2006
};
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
- };
2041
2007
2042
2008
auto &ctx = DC->getASTContext ();
2043
2009
AbstractClosureExpr *ACE = nullptr ;
@@ -2050,17 +2016,6 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
2050
2016
}
2051
2017
}
2052
2018
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
-
2064
2019
const_cast <Expr *>(E)->walk (DiagnoseWalker (ctx, ACE));
2065
2020
}
2066
2021
0 commit comments