@@ -1554,7 +1554,7 @@ Optional<BraceStmt *> TypeChecker::applyResultBuilderBodyTransform(
15541554
15551555 ctx.Diags .diagnose (
15561556 returnStmts.front ()->getReturnLoc (),
1557- diag::result_builder_disabled_by_return , builderType);
1557+ diag::result_builder_disabled_by_return_warn , builderType);
15581558
15591559 // Note that one can remove the result builder attribute.
15601560 auto attr = func->getAttachedResultBuilder ();
@@ -1671,7 +1671,7 @@ ConstraintSystem::matchResultBuilder(
16711671 if (InvalidResultBuilderBodies.count (fn)) {
16721672 (void )recordFix (
16731673 IgnoreInvalidResultBuilderBody::duringConstraintGeneration (
1674- *this , getConstraintLocator (fn.getBody ())));
1674+ *this , getConstraintLocator (fn.getAbstractClosureExpr ())));
16751675 return getTypeMatchSuccess ();
16761676 }
16771677
@@ -1690,13 +1690,25 @@ ConstraintSystem::matchResultBuilder(
16901690 return getTypeMatchFailure (locator);
16911691
16921692 if (recordFix (IgnoreInvalidResultBuilderBody::duringPreCheck (
1693- *this , getConstraintLocator (fn.getBody ()))))
1693+ *this , getConstraintLocator (fn.getAbstractClosureExpr ()))))
16941694 return getTypeMatchFailure (locator);
16951695
16961696 return getTypeMatchSuccess ();
16971697 }
16981698
16991699 case ResultBuilderBodyPreCheck::HasReturnStmt:
1700+ // Diagnostic mode means that solver couldn't reach any viable
1701+ // solution, so let's diagnose presence of a `return` statement
1702+ // in the closure body.
1703+ if (shouldAttemptFixes ()) {
1704+ if (recordFix (IgnoreResultBuilderWithReturnStmts::create (
1705+ *this , builderType,
1706+ getConstraintLocator (fn.getAbstractClosureExpr ()))))
1707+ return getTypeMatchFailure (locator);
1708+
1709+ return getTypeMatchSuccess ();
1710+ }
1711+
17001712 // If the body has a return statement, suppress the transform but
17011713 // continue solving the constraint system.
17021714 return None;
@@ -1744,7 +1756,7 @@ ConstraintSystem::matchResultBuilder(
17441756
17451757 if (recordFix (
17461758 IgnoreInvalidResultBuilderBody::duringConstraintGeneration (
1747- *this , getConstraintLocator (fn.getBody ()))))
1759+ *this , getConstraintLocator (fn.getAbstractClosureExpr ()))))
17481760 return getTypeMatchFailure (locator);
17491761
17501762 return getTypeMatchSuccess ();
0 commit comments