@@ -7808,23 +7808,31 @@ bool ConstraintSystem::applySolutionFixes(Expr *E, const Solution &solution) {
78087808 if (fixes == fixesPerExpr.end ())
78097809 return false ;
78107810
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;
78157823 };
78167824
7817- bool diagnosed = false ;
7825+ bool diagnosedError = false ;
78187826 E->forEachChildExpr ([&](Expr *subExpr) -> Expr * {
78197827 // Diagnose root expression at the end to
78207828 // preserve ordering.
78217829 if (subExpr != E)
7822- diagnosed |= diagnoseExprFailures (subExpr);
7830+ diagnosedError |= diagnoseExprFailures (subExpr);
78237831 return subExpr;
78247832 });
78257833
7826- diagnosed |= diagnoseExprFailures (E);
7827- return diagnosed ;
7834+ diagnosedError |= diagnoseExprFailures (E);
7835+ return diagnosedError ;
78287836}
78297837
78307838// / Apply a given solution to the expression, producing a fully
@@ -7839,15 +7847,21 @@ Expr *ConstraintSystem::applySolution(Solution &solution, Expr *expr,
78397847 if (shouldSuppressDiagnostics ())
78407848 return nullptr ;
78417849
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 ;
78467859
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+ }
78517865 }
78527866
78537867 // Mark any normal conformances used in this solution as "used".
0 commit comments