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

RS2008 false-negative with target-typed 'new' expression #6393

Closed
david-acker opened this issue Dec 30, 2022 · 2 comments
Closed

RS2008 false-negative with target-typed 'new' expression #6393

david-acker opened this issue Dec 30, 2022 · 2 comments

Comments

@david-acker
Copy link
Member

david-acker commented Dec 30, 2022

Analyzer

Diagnostic ID: RS2008: Enable analyzer release tracking

Analyzer source

NuGet Package: Microsoft.CodeAnalysis.Analyzers

Version: 3.3.3 (transitive dependency of Microsoft.CodeAnalysis.CSharp Version 4.4.0 )

Describe the bug

The DiagnosticDescriptionCreationAnalyzer does not report RS2008 if a target-typed 'new' expression is used to instantiate the DiagnosticDescriptor.

Steps to Reproduce

  1. Create a new C# project in Visual Studio.
  2. Install the Microsoft.CodeAnalysis.CSharp NuGet package.
  3. Copy the following code sample:
using Microsoft.CodeAnalysis;

public class Test
{
    // Correctly reports RS2008 on the DiagnosticDescriptor "id" parameter 
    public static readonly DiagnosticDescriptor DiagnosticWithExplicitType = new DiagnosticDescriptor(
        "TEST0001",
        "Title",
        "Message",
        "Category",
        DiagnosticSeverity.Error,
        isEnabledByDefault: true);

    // Does not report RS2008
    public static readonly DiagnosticDescriptor DiagnosticWithTargetTypedExpression = new(
        "TEST0002",
        "Title",
        "Message",
        "Category",
        DiagnosticSeverity.Error,
        isEnabledByDefault: true);
}

Expected behavior

The analyzer should report RS2008 when the DiagnosticDescriptor is instantiated using a target-typed expression.

Actual behavior

The analyzer does not report the diagnostic.

Note

This issue only seems to occur when the analyzer is run by Visual Studio. Updating the tests ReleaseTrackingAnalyzerTests to use a target-typed 'new' expression doesn't cause any test failures related to this issue.

@Youssef1313
Copy link
Member

Youssef1313 commented Dec 31, 2022

This was fixed in #6119

Can you try with newer versions? e.g, 3.3.4-beta1.22559.1

Releasing a stable 3.3.4 is tracked by #6290

I'm going to close as this is already fixed. If you're seeing the issue in the latest 3.3.4-beta, please open an issue with a repro project.

@david-acker
Copy link
Member Author

Ah that explains why unit tests passed then.

I updated Microsoft.CodeAnalysis.Analyzers to the most recent prerelease version and am not seeing the issue anymore. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants