Constify DiagnosticState::determineBehavior

Split out the state mutation into a new `updateFor`
function that we call for diagnostic emission, allowing
`DiagnosticTransaction::hasErrors` to query the behavior without
mutating any state.
This commit is contained in:
Hamish Knight
2025-07-02 17:46:10 +01:00
parent 98b1494b0c
commit a18f72c29a
2 changed files with 17 additions and 9 deletions

View File

@@ -618,7 +618,10 @@ namespace swift {
/// Figure out the Behavior for the given diagnostic, taking current
/// state such as fatality into account.
DiagnosticBehavior determineBehavior(const Diagnostic &diag);
DiagnosticBehavior determineBehavior(const Diagnostic &diag) const;
/// Updates the diagnostic state for a diagnostic to emit.
void updateFor(DiagnosticBehavior behavior);
bool hadAnyError() const { return anyErrorOccurred; }
bool hasFatalErrorOccurred() const { return fatalErrorOccurred; }
@@ -646,7 +649,7 @@ namespace swift {
/// Returns a Boolean value indicating whether warnings belonging to the
/// diagnostic group identified by `id` should be escalated to errors.
bool getWarningsAsErrorsForDiagGroupID(DiagGroupID id) {
bool getWarningsAsErrorsForDiagGroupID(DiagGroupID id) const {
return warningsAsErrors[(unsigned)id];
}