From e4a27cf497817e5fdc5a1353b8520a38ff6ff39b Mon Sep 17 00:00:00 2001 From: Manish Vasani Date: Wed, 19 Jun 2019 13:52:41 -0700 Subject: [PATCH] Adjust unsuppressed error check and doc comments. --- .../Core/Portable/CommandLine/CommonCompiler.cs | 13 +++++++------ .../Core/Portable/Compilation/Compilation.cs | 5 ++--- .../Core/Portable/Diagnostic/Diagnostic.cs | 8 ++++++++ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs b/src/Compilers/Core/Portable/CommandLine/CommonCompiler.cs index 4b9328c1021..7509d19211d 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 935a0e7862c..60e06d60679 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 b7d2b546f48..e7b8eb615f7 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(); } /// -- GitLab