@@ -1464,7 +1464,7 @@ Optional<BraceStmt *> TypeChecker::applyFunctionBuilderBodyTransform(
1464
1464
// If we encountered an error or there was an explicit result type,
1465
1465
// bail out and report that to the caller.
1466
1466
auto &ctx = func->getASTContext ();
1467
- auto request = PreCheckFunctionBuilderRequest{func};
1467
+ auto request = PreCheckFunctionBuilderRequest{func, func-> getBody () };
1468
1468
switch (evaluateOrDefault (
1469
1469
ctx.evaluator , request, FunctionBuilderBodyPreCheck::Error)) {
1470
1470
case FunctionBuilderBodyPreCheck::Okay:
@@ -1592,7 +1592,7 @@ ConstraintSystem::matchFunctionBuilder(
1592
1592
1593
1593
// Pre-check the body: pre-check any expressions in it and look
1594
1594
// for return statements.
1595
- auto request = PreCheckFunctionBuilderRequest{fn};
1595
+ auto request = PreCheckFunctionBuilderRequest{fn, fn. getBody () };
1596
1596
switch (evaluateOrDefault (getASTContext ().evaluator , request,
1597
1597
FunctionBuilderBodyPreCheck::Error)) {
1598
1598
case FunctionBuilderBodyPreCheck::Okay:
@@ -1755,8 +1755,14 @@ class PreCheckFunctionBuilderApplication : public ASTWalker {
1755
1755
}
1756
1756
1757
1757
FunctionBuilderBodyPreCheck
1758
- PreCheckFunctionBuilderRequest::evaluate (Evaluator &eval,
1759
- AnyFunctionRef fn) const {
1758
+ PreCheckFunctionBuilderRequest::evaluate (Evaluator &eval, AnyFunctionRef fn,
1759
+ BraceStmt *body) const {
1760
+ // NOTE: 'body' is passed only for the request evaluater caching key.
1761
+ // Since source tooling (e.g. code completion) might replace the body,
1762
+ // the function alone is not sufficient for the key.
1763
+ assert (fn.getBody () == body &&
1764
+ " body must be the current body of the function" );
1765
+
1760
1766
// We don't want to do the precheck if it will already have happened in
1761
1767
// the enclosing expression.
1762
1768
bool skipPrecheck = false ;
0 commit comments