@@ -1263,7 +1263,8 @@ llvm::cl::opt<bool> AssertOnError("swift-diagnostics-assert-on-error",
12631263llvm::cl::opt<bool > AssertOnWarning (" swift-diagnostics-assert-on-warning" ,
12641264 llvm::cl::init (false ));
12651265
1266- DiagnosticBehavior DiagnosticState::determineBehavior (const Diagnostic &diag) {
1266+ DiagnosticBehavior
1267+ DiagnosticState::determineBehavior (const Diagnostic &diag) const {
12671268 // We determine how to handle a diagnostic based on the following rules
12681269 // 1) Map the diagnostic to its "intended" behavior, applying the behavior
12691270 // limit for this particular emission
@@ -1310,21 +1311,23 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
13101311 if (suppressRemarks)
13111312 lvl = DiagnosticBehavior::Ignore;
13121313 }
1314+ return lvl;
1315+ }
13131316
1314- // 5) Update current state for use during the next diagnostic
1315- if (lvl == DiagnosticBehavior::Fatal) {
1317+ void DiagnosticState::updateFor (DiagnosticBehavior behavior) {
1318+ // Update current state for use during the next diagnostic
1319+ if (behavior == DiagnosticBehavior::Fatal) {
13161320 fatalErrorOccurred = true ;
13171321 anyErrorOccurred = true ;
1318- } else if (lvl == DiagnosticBehavior::Error) {
1322+ } else if (behavior == DiagnosticBehavior::Error) {
13191323 anyErrorOccurred = true ;
13201324 }
13211325
13221326 ASSERT ((!AssertOnError || !anyErrorOccurred) && " We emitted an error?!" );
1323- ASSERT ((!AssertOnWarning || (lvl != DiagnosticBehavior::Warning)) &&
1327+ ASSERT ((!AssertOnWarning || (behavior != DiagnosticBehavior::Warning)) &&
13241328 " We emitted a warning?!" );
13251329
1326- previousBehavior = lvl;
1327- return lvl;
1330+ previousBehavior = behavior;
13281331}
13291332
13301333void DiagnosticEngine::flushActiveDiagnostic () {
@@ -1369,6 +1372,8 @@ std::optional<DiagnosticInfo>
13691372DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic,
13701373 bool includeDiagnosticName) {
13711374 auto behavior = state.determineBehavior (diagnostic);
1375+ state.updateFor (behavior);
1376+
13721377 if (behavior == DiagnosticBehavior::Ignore)
13731378 return std::nullopt ;
13741379
0 commit comments