@@ -7808,23 +7808,31 @@ bool ConstraintSystem::applySolutionFixes(Expr *E, const Solution &solution) {
7808
7808
if (fixes == fixesPerExpr.end ())
7809
7809
return false ;
7810
7810
7811
- bool diagnosed = false ;
7812
- for (const auto *fix : fixes->second )
7813
- diagnosed |= fix->diagnose (E);
7814
- return diagnosed;
7811
+ bool diagnosedError = false ;
7812
+ for (const auto *fix : fixes->second ) {
7813
+ auto diagnosed = fix->diagnose (E);
7814
+
7815
+ if (fix->isWarning ()) {
7816
+ assert (diagnosed && " warnings should always be diagnosed" );
7817
+ (void )diagnosed;
7818
+ } else {
7819
+ diagnosedError |= diagnosed;
7820
+ }
7821
+ }
7822
+ return diagnosedError;
7815
7823
};
7816
7824
7817
- bool diagnosed = false ;
7825
+ bool diagnosedError = false ;
7818
7826
E->forEachChildExpr ([&](Expr *subExpr) -> Expr * {
7819
7827
// Diagnose root expression at the end to
7820
7828
// preserve ordering.
7821
7829
if (subExpr != E)
7822
- diagnosed |= diagnoseExprFailures (subExpr);
7830
+ diagnosedError |= diagnoseExprFailures (subExpr);
7823
7831
return subExpr;
7824
7832
});
7825
7833
7826
- diagnosed |= diagnoseExprFailures (E);
7827
- return diagnosed ;
7834
+ diagnosedError |= diagnoseExprFailures (E);
7835
+ return diagnosedError ;
7828
7836
}
7829
7837
7830
7838
// / Apply a given solution to the expression, producing a fully
@@ -7839,15 +7847,21 @@ Expr *ConstraintSystem::applySolution(Solution &solution, Expr *expr,
7839
7847
if (shouldSuppressDiagnostics ())
7840
7848
return nullptr ;
7841
7849
7842
- // If we can diagnose the problem with the fixits that we've pre-assumed,
7843
- // do so now.
7844
- if (applySolutionFixes (expr, solution))
7845
- return nullptr ;
7850
+ bool diagnosedErrorsViaFixes = applySolutionFixes (expr, solution);
7851
+ // If all of the available fixes would result in a warning,
7852
+ // we can go ahead and apply this solution to AST.
7853
+ if (!llvm::all_of (solution.Fixes , [](const ConstraintFix *fix) {
7854
+ return fix->isWarning ();
7855
+ })) {
7856
+ // If we already diagnosed any errors via fixes, that's it.
7857
+ if (diagnosedErrorsViaFixes)
7858
+ return nullptr ;
7846
7859
7847
- // If we didn't manage to diagnose anything well, so fall back to
7848
- // diagnosing mining the system to construct a reasonable error message.
7849
- diagnoseFailureForExpr (expr);
7850
- return nullptr ;
7860
+ // If we didn't manage to diagnose anything well, so fall back to
7861
+ // diagnosing mining the system to construct a reasonable error message.
7862
+ diagnoseFailureForExpr (expr);
7863
+ return nullptr ;
7864
+ }
7851
7865
}
7852
7866
7853
7867
// Mark any normal conformances used in this solution as "used".
0 commit comments