Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'DiagnosticSuppressor' doesn't work at all when targeting IDEXXXX diagnostics #76111

Closed
Sergio0694 opened this issue Nov 27, 2024 · 1 comment
Labels
Area-Analyzers Resolution-Duplicate The described behavior is tracked in another issue

Comments

@Sergio0694
Copy link
Contributor

Version Used: 4.12.0-3.24558.5 (21192bf)

Overview

This issue is blocking microsoft/CsWinRT#1878. It seems that diagnostic suppressors are not invoked at all by Roslyn when targeting IDEXXXX diagnostics. If I take the same exact suppressor and just change the suppressed id to some CSXXXX diagnostic, then it is invoked as expected. When I change it back to IDEXXXX, it stops working again. Interestingly enough, it does run in a unit test, but not in a real project. I tried both when referencing a .dll from a NuGet package, as well as with a local project reference. ReportSuppressions is never called.

Steps to Reproduce:

  1. Use a suppressor like this:
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class CollectionExpressionIDE0300Suppressor : DiagnosticSuppressor
{
    public static readonly SuppressionDescriptor CollectionExpressionIDE0300 = new(
        id: "CsWinRT2001",
        suppressedDiagnosticId: "IDE0300",
        justification:
            "Using collection expressions when targeting 'IEnumerable<T>', 'ICollection<T>', 'IList<T>', 'IReadOnlyCollection<T>', " +
            "or 'IReadOnlyList<T>', when the collection expression is not empty, is not AOT compatible in WinRT scenarios");

    /// <inheritdoc/>
    public override ImmutableArray<SuppressionDescriptor> SupportedSuppressions { get; } = [CollectionExpressionIDE0300];

    /// <inheritdoc/>
    public override void ReportSuppressions(SuppressionAnalysisContext context)
    {
        Debugger.Launch();
        Debugger.Break();
    }
}
  1. Reference it in a project
  2. Cause the diagnostic to be produced, eg. in this case via:
int[] x = new[] { 1, 2, 3 };
  1. Observe that ReportSuppressions is never invoked at all.

I can provide logs or anything else needed.

Expected Behavior:

The suppressor should work as expected.

Actual Behavior:

The suppressor is never invoked at all when targeting IDEXXXX diagnostics.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 27, 2024
@JoeRobich JoeRobich added the Resolution-Duplicate The described behavior is tracked in another issue label Nov 27, 2024
@JoeRobich
Copy link
Member

Duplicate of #75399. This is fixed by #75684. The fix will be in the next 17.12 servicing release as well as 17.13 previews.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged Issues and PRs which have not yet been triaged by a lead label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Analyzers Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

2 participants