Skip to content

CompilationWithAnalyzersOptions.ReportSuppressedDiagnostics property has no effect on DiagnosticSuppressor #52953

@safu9

Description

@safu9

When CompilationWithAnalyzersOptions.ReportSuppressedDiagnostics is set to true,
CompilationWithAnalyzers doesn't return diagnostics suppressed by pragma or SuppressMessageAttribute,
but return diagnostics suppressed by DiagnosticSuppressors.

The docs for ReportSuppressedDiagnostics say this flag filters diagnostics with IsSuppressed.
Diagnostics suppressed by DiagnosticSuppressors also have IsSuppressed, so I think the docs or the implementation must be corrected.

Example code:

var compilationWithAnalyzers = compilation.WithAnalyzers(analyzers, new CompilationWithAnalyzersOptions(
    options,
    onAnalyzerException: null,
    concurrentAnalysis: false,
    logAnalyzerExecutionTime: false,
    reportSuppressedDiagnostics: false));  // here

var diagnostics = await compilationWithAnalyzers
    .GetAnalyzerSemanticDiagnosticsAsync(semanticModel, filterSpan: null, cancellationToken);

Expected Behavior:
diagnostics don't include any diagnostics suppressed by DiagnosticSuppressors.

Actual Behavior:
diagnostics include diagnostics suppressed by DiagnosticSuppressors.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions