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

CA1508 fires for Debug.Assert #6983

Closed
tannergooding opened this issue Oct 15, 2023 · 0 comments · Fixed by #7014
Closed

CA1508 fires for Debug.Assert #6983

tannergooding opened this issue Oct 15, 2023 · 0 comments · Fixed by #7014
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers DataFlow False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting
Milestone

Comments

@tannergooding
Copy link
Member

Analyzer

Diagnostic ID: CA1508: Avoid dead conditional code

Steps To Reproduce

  1. Create a new C# Class Library, targeting net8.0
  2. Edit the csproj and add <AnalysisLevel>latest-all</AnalysisLevel>
  3. Define the following class:
using System.Diagnostics;

namespace MyNamespace;

public static class MyClass1
{
    internal const int MyConstant = 16;

    public static void MyMethod()
    {
        Debug.Assert(MyConstant == 16);
    }
}

Expected behavior

The analyzer should not trigger for a Debug.Assert. This is often used to handle code that may make assumptions based on the value of a constant, such as not handling larger code paths or having pre-defined static data and where it may need to be updated if the value of the constant ever changes.

Actual behavior

The analyzer is triggered.

@mavasani mavasani added Area-Microsoft.CodeQuality.Analyzers DataFlow False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting labels Oct 23, 2023
@mavasani mavasani added this to the Unknown milestone Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers DataFlow False_Positive A diagnostic is reported for non-problematic case help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants