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 false positive & inconsistency #7435

Open
RobSwDev opened this issue Oct 4, 2024 · 0 comments
Open

CA1508 false positive & inconsistency #7435

RobSwDev opened this issue Oct 4, 2024 · 0 comments

Comments

@RobSwDev
Copy link

RobSwDev commented Oct 4, 2024

Analyzer

Diagnostic ID: CA1508: Avoid dead conditional code

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: [SDK 8.0.400]

Also repro'd when installing Version: 8.0.0 explicitly.

Describe the bug

Dead-code analysis shows false-positives.
In the attached example (& screenshot below) the methods CreateSomething and KreateSomething are identical, and can return null.
However, the analyser objects to the null check for the return value of one method, but not the other.

image

Steps To Reproduce

Load the attached solution into VS2022 and compile.

Expected behavior

No CA1508 warnings should be raised

Actual behavior

False positive warning is raised.

ConsoleApp1.zip

[A weird quirk is that the analyser does not show this false positive in the duplicate code in Program.cs, which uses the new console template. Is such code treated differently?]

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

No branches or pull requests

1 participant