@@ -1523,6 +1523,14 @@ ConstraintSystem::matchFunctionBuilder(
15231523 assert (builder && " Bad function builder type" );
15241524 assert (builder->getAttrs ().hasAttribute <FunctionBuilderAttr>());
15251525
1526+ if (InvalidFunctionBuilderBodies.count (fn)) {
1527+ auto *closure = cast<ClosureExpr>(fn.getAbstractClosureExpr ());
1528+ (void )recordFix (
1529+ IgnoreInvalidFunctionBuilderBody::duringConstraintGeneration (
1530+ *this , getConstraintLocator (closure)));
1531+ return getTypeMatchSuccess ();
1532+ }
1533+
15261534 // Pre-check the body: pre-check any expressions in it and look
15271535 // for return statements.
15281536 auto request = PreCheckFunctionBuilderRequest{fn, fn.getBody (),
@@ -1539,7 +1547,7 @@ ConstraintSystem::matchFunctionBuilder(
15391547
15401548 if (auto *closure =
15411549 dyn_cast_or_null<ClosureExpr>(fn.getAbstractClosureExpr ())) {
1542- auto failed = recordFix (IgnoreInvalidFunctionBuilderBody::create (
1550+ auto failed = recordFix (IgnoreInvalidFunctionBuilderBody::duringPreCheck (
15431551 *this , getConstraintLocator (closure)));
15441552 return failed ? getTypeMatchFailure (locator) : getTypeMatchSuccess ();
15451553 }
@@ -1598,9 +1606,27 @@ ConstraintSystem::matchFunctionBuilder(
15981606 BuilderClosureVisitor visitor (getASTContext (), this , dc, builderType,
15991607 bodyResultType);
16001608
1601- auto applied = visitor.apply (fn.getBody ());
1602- if (!applied)
1603- return getTypeMatchFailure (locator);
1609+ Optional<AppliedBuilderTransform> applied = None;
1610+ {
1611+ DiagnosticTransaction transaction (dc->getASTContext ().Diags );
1612+
1613+ applied = visitor.apply (fn.getBody ());
1614+ if (!applied)
1615+ return getTypeMatchFailure (locator);
1616+
1617+ if (transaction.hasErrors ()) {
1618+ if (auto *closure =
1619+ dyn_cast_or_null<ClosureExpr>(fn.getAbstractClosureExpr ())) {
1620+ InvalidFunctionBuilderBodies.insert (fn);
1621+ auto failed = recordFix (
1622+ IgnoreInvalidFunctionBuilderBody::duringConstraintGeneration (
1623+ *this , getConstraintLocator (closure)));
1624+ return failed ? getTypeMatchFailure (locator) : getTypeMatchSuccess ();
1625+ }
1626+
1627+ return getTypeMatchFailure (locator);
1628+ }
1629+ }
16041630
16051631 Type transformedType = getType (applied->returnExpr );
16061632 assert (transformedType && " Missing type" );
@@ -1687,7 +1713,7 @@ class PreCheckFunctionBuilderApplication : public ASTWalker {
16871713
16881714 HasError |= ConstraintSystem::preCheckExpression (
16891715 E, DC, /* replaceInvalidRefsWithErrors=*/ false );
1690- HasError |= transaction.hasDiagnostics ();
1716+ HasError |= transaction.hasErrors ();
16911717
16921718 if (SuppressDiagnostics)
16931719 transaction.abort ();
0 commit comments