@@ -2462,8 +2462,11 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
2462
2462
return getTypeMatchSuccess ();
2463
2463
}
2464
2464
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.
2467
2470
auto request =
2468
2471
PreCheckResultBuilderRequest{{fn, /* SuppressDiagnostics=*/ false }};
2469
2472
switch (evaluateOrDefault (getASTContext ().evaluator , request,
@@ -2473,16 +2476,10 @@ ConstraintSystem::matchResultBuilder(AnyFunctionRef fn, Type builderType,
2473
2476
break ;
2474
2477
2475
2478
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 ;
2486
2483
}
2487
2484
2488
2485
case ResultBuilderBodyPreCheck::HasReturnStmt:
@@ -2800,8 +2797,11 @@ class PreCheckResultBuilderApplication : public ASTWalker {
2800
2797
2801
2798
ResultBuilderBodyPreCheck PreCheckResultBuilderRequest::evaluate (
2802
2799
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 ();
2803
2803
return PreCheckResultBuilderApplication (
2804
- owner.Fn , /* skipPrecheck= */ false ,
2804
+ owner.Fn , skipPrecheck,
2805
2805
/* suppressDiagnostics=*/ owner.SuppressDiagnostics )
2806
2806
.run ();
2807
2807
}
0 commit comments