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

CA1862 false positive with the same variable on both sides of the comparison #7074

Open
xiety opened this issue Dec 7, 2023 · 0 comments · May be fixed by #7517
Open

CA1862 false positive with the same variable on both sides of the comparison #7074

xiety opened this issue Dec 7, 2023 · 0 comments · May be fixed by #7517
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design 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

@xiety
Copy link

xiety commented Dec 7, 2023

Analyzer

Diagnostic ID: CA1862: Use the 'StringComparison' method overloads to perform case-insensitive string comparisons

Analyzer source

SDK: Built-in CA analyzers in .NET 8 SDK

Version: SDK 8.0.100

Describe the bug

CA1862 should not be shown when the same variable is on both sides of the comparison.

Steps To Reproduce

if (name.ToLower() == name)
    Console.WriteLine("all letters are lowercase");

And the suggested fix changes the behavior completely:

// always true now
if (name.Equals(name, StringComparison.CurrentCultureIgnoreCase))
    Console.WriteLine("all letters are lowercase");
@sharwell sharwell added the False_Positive A diagnostic is reported for non-problematic case label Dec 19, 2023
@mavasani mavasani added Bug The product is not behaving according to its current intended design Area-Microsoft.CodeAnalysis.NetAnalyzers help wanted The issue is up-for-grabs, and can be claimed by commenting labels Jan 2, 2024
@mavasani mavasani added this to the .NET vNext milestone Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Microsoft.CodeAnalysis.NetAnalyzers Bug The product is not behaving according to its current intended design 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.

3 participants