@@ -1263,7 +1263,8 @@ llvm::cl::opt<bool> AssertOnError("swift-diagnostics-assert-on-error",
1263
1263
llvm::cl::opt<bool > AssertOnWarning (" swift-diagnostics-assert-on-warning" ,
1264
1264
llvm::cl::init (false ));
1265
1265
1266
- DiagnosticBehavior DiagnosticState::determineBehavior (const Diagnostic &diag) {
1266
+ DiagnosticBehavior
1267
+ DiagnosticState::determineBehavior (const Diagnostic &diag) const {
1267
1268
// We determine how to handle a diagnostic based on the following rules
1268
1269
// 1) Map the diagnostic to its "intended" behavior, applying the behavior
1269
1270
// limit for this particular emission
@@ -1310,21 +1311,23 @@ DiagnosticBehavior DiagnosticState::determineBehavior(const Diagnostic &diag) {
1310
1311
if (suppressRemarks)
1311
1312
lvl = DiagnosticBehavior::Ignore;
1312
1313
}
1314
+ return lvl;
1315
+ }
1313
1316
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) {
1316
1320
fatalErrorOccurred = true ;
1317
1321
anyErrorOccurred = true ;
1318
- } else if (lvl == DiagnosticBehavior::Error) {
1322
+ } else if (behavior == DiagnosticBehavior::Error) {
1319
1323
anyErrorOccurred = true ;
1320
1324
}
1321
1325
1322
1326
ASSERT ((!AssertOnError || !anyErrorOccurred) && " We emitted an error?!" );
1323
- ASSERT ((!AssertOnWarning || (lvl != DiagnosticBehavior::Warning)) &&
1327
+ ASSERT ((!AssertOnWarning || (behavior != DiagnosticBehavior::Warning)) &&
1324
1328
" We emitted a warning?!" );
1325
1329
1326
- previousBehavior = lvl;
1327
- return lvl;
1330
+ previousBehavior = behavior;
1328
1331
}
1329
1332
1330
1333
void DiagnosticEngine::flushActiveDiagnostic () {
@@ -1369,6 +1372,8 @@ std::optional<DiagnosticInfo>
1369
1372
DiagnosticEngine::diagnosticInfoForDiagnostic (const Diagnostic &diagnostic,
1370
1373
bool includeDiagnosticName) {
1371
1374
auto behavior = state.determineBehavior (diagnostic);
1375
+ state.updateFor (behavior);
1376
+
1372
1377
if (behavior == DiagnosticBehavior::Ignore)
1373
1378
return std::nullopt;
1374
1379
0 commit comments