Skip to content

Commit 10878e8

Browse files
committed
Tweak ClosureExpr inference instead
1 parent 8b193a2 commit 10878e8

File tree

2 files changed

+1
-46
lines changed

2 files changed

+1
-46
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7115,7 +7115,7 @@ bool ConstraintSystem::participatesInInference(ClosureExpr *closure) const {
71157115

71167116
// If body is nested in a parent that has a function builder applied,
71177117
// let's prevent inference until result builders.
7118-
if (Options.contains(
7118+
if (isForCodeCompletion() && Options.contains(
71197119
ConstraintSystemFlags::
71207120
ClosuresInResultBuildersDontParticipateInInference)) {
71217121
return !isInResultBuilderContext(closure);

lib/Sema/MiscDiagnostics.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)