diff --git a/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs b/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs index 4b9328c1021122c8ce24997aa8b949533eb70fc2..7509d19211d9e6bc92a6b081250ddd2b6bdb0de4 100644 --- a/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs +++ b/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs @@ -560,18 +560,19 @@ internal bool ReportDiagnostics(IEnumerable diagnostics, TextWri => ReportDiagnostics(diagnostics.Select(info => Diagnostic.Create(info)), consoleOutput, errorLoggerOpt); /// - /// Returns true if there are any diagnostics in the bag which have default severity error and are - /// not marked "suppressed". Note: does NOT do filtering, so it may return false if a + /// Returns true if there are any error diagnostics in the bag which cannot be suppressed and + /// are guaranteed to break the build. + /// Only diagnostics which have default severity error and are tagged as NotConfigurable fall in this bucket. + /// This includes all compiler error diagnostics and specific analyzer error diagnostics that are marked as not configurable by the analyzer author. + /// Note: does NOT do filtering, so it may return false if a /// non-error diagnostic were later elevated to an error through filtering (e.g., through - /// warn-as-error). This is meant to be a check if there are any "real" errors, in the bag - /// since diagnostics with default "error" severity can never be suppressed or reduced - /// below error severity. + /// warn-as-error). /// internal static bool HasUnsuppressedErrors(DiagnosticBag diagnostics) { foreach (var diag in diagnostics.AsEnumerable()) { - if (diag.DefaultSeverity == DiagnosticSeverity.Error && !diag.IsSuppressed) + if (diag.IsUnsuppressedError()) { return true; } diff --git a/src/Compilers/Core/Portable/Compilation/Compilation.cs b/src/Compilers/Core/Portable/Compilation/Compilation.cs index 935a0e7862c2955d263721cd931d2b634def1597..60e06d606794a4cd8de22f3206066956fa4903df 100644 --- a/src/Compilers/Core/Portable/Compilation/Compilation.cs +++ b/src/Compilers/Core/Portable/Compilation/Compilation.cs @@ -1347,7 +1347,7 @@ internal void CompleteCompilationEventQueue_NoLock() /// /// Bag to which filtered diagnostics will be added. /// Diagnostics to be filtered. - /// True if there were no errors. + /// True if there are no unsuppressed errors (i.e., no errors which fail compilation). internal bool FilterAndAppendAndFreeDiagnostics(DiagnosticBag accumulator, ref DiagnosticBag incoming) { bool result = FilterAndAppendDiagnostics(accumulator, incoming.AsEnumerableWithoutResolution(), exclude: null); @@ -1378,8 +1378,7 @@ internal bool FilterAndAppendDiagnostics(DiagnosticBag accumulator, IEnumerable< { continue; } - else if (filtered.DefaultSeverity == DiagnosticSeverity.Error && - !filtered.IsSuppressed) + else if (filtered.IsUnsuppressedError()) { hasError = true; } diff --git a/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs b/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs index b7d2b546f48d68ec088a18d04c7b9e7744b6d1be..e7b8eb615f78604a1753f0bd892751b1175cdda3 100644 --- a/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs +++ b/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs @@ -559,6 +559,14 @@ internal virtual bool IsNotConfigurable() { return AnalyzerManager.HasNotConfigurableTag(this.CustomTags); } + + /// + /// Returns true if this is an error diagnostic which cannot be suppressed and is guaranteed to break the build. + /// Only diagnostics which have default severity error and are tagged as NotConfigurable fall in this bucket. + /// This includes all compiler error diagnostics and specific analyzer error diagnostics that are marked as not configurable by the analyzer author. + /// + internal bool IsUnsuppressedError() + => DefaultSeverity == DiagnosticSeverity.Error && IsNotConfigurable(); } ///