@@ -1287,7 +1287,8 @@ llvm::cl::opt<bool> AssertOnError("swift-diagnostics-assert-on-error",
1287
1287
llvm::cl::opt<bool > AssertOnWarning (" swift-diagnostics-assert-on-warning" ,
1288
1288
llvm::cl::init (false ));
1289
1289
1290
- DiagnosticBehavior DiagnosticState::determineBehavior (const Diagnostic &diag) {
1290
+ DiagnosticBehavior
1291
+ DiagnosticState::determineBehavior (const Diagnostic &diag) const {
1291
1292
// We determine how to handle a diagnostic based on the following rules
1292
1293
// 1) Map the diagnostic to its "intended" behavior, applying the behavior
1293
1294
// limit for this particular emission
@@ -1334,21 +1335,23 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
1334
1335
if (suppressRemarks)
1335
1336
lvl = DiagnosticBehavior::Ignore;
1336
1337
}
1338
+ return lvl;
1339
+ }
1337
1340
1338
- // 5) Update current state for use during the next diagnostic
1339
- if (lvl == DiagnosticBehavior::Fatal) {
1341
+ void DiagnosticState::updateFor (DiagnosticBehavior behavior) {
1342
+ // Update current state for use during the next diagnostic
1343
+ if (behavior == DiagnosticBehavior::Fatal) {
1340
1344
fatalErrorOccurred = true ;
1341
1345
anyErrorOccurred = true ;
1342
- } else if (lvl == DiagnosticBehavior::Error) {
1346
+ } else if (behavior == DiagnosticBehavior::Error) {
1343
1347
anyErrorOccurred = true ;
1344
1348
}
1345
1349
1346
1350
ASSERT ((!AssertOnError || !anyErrorOccurred) && " We emitted an error?!" );
1347
- ASSERT ((!AssertOnWarning || (lvl != DiagnosticBehavior::Warning)) &&
1351
+ ASSERT ((!AssertOnWarning || (behavior != DiagnosticBehavior::Warning)) &&
1348
1352
" We emitted a warning?!" );
1349
1353
1350
- previousBehavior = lvl;
1351
- return lvl;
1354
+ previousBehavior = behavior;
1352
1355
}
1353
1356
1354
1357
void DiagnosticEngine::flushActiveDiagnostic () {
@@ -1393,6 +1396,8 @@ std::optional<DiagnosticInfo>
1393
1396
DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic,
1394
1397
bool includeDiagnosticName) {
1395
1398
auto behavior = state.determineBehavior (diagnostic);
1399
+ state.updateFor (behavior);
1400
+
1396
1401
if (behavior == DiagnosticBehavior::Ignore)
1397
1402
return std::nullopt;
1398
1403
0 commit comments