@@ -1712,7 +1712,7 @@ class PreCheckFunctionBuilderApplication : public ASTWalker {
1712
1712
1713
1713
public:
1714
1714
PreCheckFunctionBuilderApplication (AnyFunctionRef fn, bool skipPrecheck)
1715
- : Fn(fn), SkipPrecheck(skipPrecheck) {}
1715
+ : Fn(fn), SkipPrecheck(skipPrecheck) {}
1716
1716
1717
1717
const std::vector<ReturnStmt *> getReturnStmts () const { return ReturnStmts; }
1718
1718
@@ -1736,16 +1736,25 @@ class PreCheckFunctionBuilderApplication : public ASTWalker {
1736
1736
}
1737
1737
1738
1738
std::pair<bool , Expr *> walkToExprPre (Expr *E) override {
1739
+ if (SkipPrecheck)
1740
+ return std::make_pair (false , E);
1741
+
1739
1742
// Pre-check the expression. If this fails, abort the walk immediately.
1740
1743
// Otherwise, replace the expression with the result of pre-checking.
1741
1744
// In either case, don't recurse into the expression.
1742
- if (!SkipPrecheck &&
1743
- ConstraintSystem::preCheckExpression (E, /* DC*/ Fn.getAsDeclContext ())) {
1744
- HasError = true ;
1745
- return std::make_pair (false , nullptr );
1746
- }
1745
+ {
1746
+ auto *DC = Fn.getAsDeclContext ();
1747
+ auto &diagEngine = DC->getASTContext ().Diags ;
1747
1748
1748
- return std::make_pair (false , E);
1749
+ // Suppress any diangostics which could be produced by this expression.
1750
+ DiagnosticTransaction transaction (diagEngine);
1751
+
1752
+ HasError |= ConstraintSystem::preCheckExpression (E, DC);
1753
+ HasError |= transaction.hasDiagnostics ();
1754
+
1755
+ transaction.abort ();
1756
+ return std::make_pair (false , HasError ? nullptr : E);
1757
+ }
1749
1758
}
1750
1759
1751
1760
std::pair<bool , Stmt *> walkToStmtPre (Stmt *S) override {
0 commit comments