@@ -2462,8 +2462,11 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
24622462 return getTypeMatchSuccess ();
24632463 }
24642464
2465- // Pre-check the body: pre-check any expressions in it and look
2466- // for return statements.
2465+ // We have already pre-checked the result builder body. Technically, we
2466+ // shouldn't need to do anything here, but there was a bug here that we did
2467+ // not apply the result builder transform if it contained an explicit return.
2468+ // To maintain source compatibility, we still need to check for HasReturnStmt.
2469+ // https://github.com/apple/swift/issues/64332.
24672470 auto request =
24682471 PreCheckResultBuilderRequest{{fn, /* SuppressDiagnostics=*/ false }};
24692472 switch (evaluateOrDefault (getASTContext ().evaluator , request,
@@ -2473,16 +2476,10 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
24732476 break ;
24742477
24752478 case ResultBuilderBodyPreCheck::Error: {
2476- InvalidResultBuilderBodies.insert (fn);
2477-
2478- if (!shouldAttemptFixes ())
2479- return getTypeMatchFailure (locator);
2480-
2481- if (recordFix (IgnoreInvalidResultBuilderBody::create (
2482- *this , getConstraintLocator (fn.getAbstractClosureExpr ()))))
2483- return getTypeMatchFailure (locator);
2484-
2485- return getTypeMatchSuccess ();
2479+ llvm_unreachable (
2480+ " Running PreCheckResultBuilderRequest on a function shouldn't run "
2481+ " preCheckExpression and thus we should never enter this case." );
2482+ break ;
24862483 }
24872484
24882485 case ResultBuilderBodyPreCheck::HasReturnStmt:
@@ -2800,8 +2797,11 @@ class PreCheckResultBuilderApplication : public ASTWalker {
28002797
28012798ResultBuilderBodyPreCheck PreCheckResultBuilderRequest::evaluate (
28022799 Evaluator &evaluator, PreCheckResultBuilderDescriptor owner) const {
2800+ // Closures should already be pre-checked when we run this, so there's no need
2801+ // to pre-check them again.
2802+ bool skipPrecheck = owner.Fn .getAbstractClosureExpr ();
28032803 return PreCheckResultBuilderApplication (
2804- owner.Fn , /* skipPrecheck= */ false ,
2804+ owner.Fn , skipPrecheck,
28052805 /* suppressDiagnostics=*/ owner.SuppressDiagnostics )
28062806 .run ();
28072807}
0 commit comments