@@ -1523,6 +1523,14 @@ ConstraintSystem::matchFunctionBuilder(
1523
1523
assert (builder && " Bad function builder type" );
1524
1524
assert (builder->getAttrs ().hasAttribute <FunctionBuilderAttr>());
1525
1525
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
+
1526
1534
// Pre-check the body: pre-check any expressions in it and look
1527
1535
// for return statements.
1528
1536
auto request = PreCheckFunctionBuilderRequest{fn, fn.getBody (),
@@ -1539,7 +1547,7 @@ ConstraintSystem::matchFunctionBuilder(
1539
1547
1540
1548
if (auto *closure =
1541
1549
dyn_cast_or_null<ClosureExpr>(fn.getAbstractClosureExpr ())) {
1542
- auto failed = recordFix (IgnoreInvalidFunctionBuilderBody::create (
1550
+ auto failed = recordFix (IgnoreInvalidFunctionBuilderBody::duringPreCheck (
1543
1551
*this , getConstraintLocator (closure)));
1544
1552
return failed ? getTypeMatchFailure (locator) : getTypeMatchSuccess ();
1545
1553
}
@@ -1598,9 +1606,27 @@ ConstraintSystem::matchFunctionBuilder(
1598
1606
BuilderClosureVisitor visitor (getASTContext (), this , dc, builderType,
1599
1607
bodyResultType);
1600
1608
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
+ }
1604
1630
1605
1631
Type transformedType = getType (applied->returnExpr );
1606
1632
assert (transformedType && " Missing type" );
@@ -1687,7 +1713,7 @@ class PreCheckFunctionBuilderApplication : public ASTWalker {
1687
1713
1688
1714
HasError |= ConstraintSystem::preCheckExpression (
1689
1715
E, DC, /* replaceInvalidRefsWithErrors=*/ false );
1690
- HasError |= transaction.hasDiagnostics ();
1716
+ HasError |= transaction.hasErrors ();
1691
1717
1692
1718
if (SuppressDiagnostics)
1693
1719
transaction.abort ();
0 commit comments