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

CA1861 code fix doesn't use unique name #6981

Closed
meziantou opened this issue Oct 14, 2023 · 0 comments · Fixed by #7013
Closed

CA1861 code fix doesn't use unique name #6981

meziantou opened this issue Oct 14, 2023 · 0 comments · Fixed by #7013
Labels
Area-CodeFix Bug in code fixer Bug The product is not behaving according to its current intended design good first issue help wanted The issue is up-for-grabs, and can be claimed by commenting
Milestone

Comments

@meziantou
Copy link

meziantou commented Oct 14, 2023

Analyzer

Diagnostic ID: CA1861: Extract to static readonly field

Analyzer source

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

Version: SDK 8.0.0-rc2

Describe the bug

CA1861 code fix creates a new field that can have the same name as a local variable

image

Steps To Reproduce

Original code:

class Sample
{
    void A(char separator)
    {
        "".Split(new char[] { 'a', 'b' });
    }
}

After code fix:

class Sample
{
    internal static readonly char[] separator = new char[] { 'a', 'b' };

    void A(char separator)
    {
        // "separator" is the local parameter instead of the static field
        "".Split(separator);
    }
}

Expected behavior

Generate a unique name

Actual behavior

Additional context

@mavasani mavasani added Bug The product is not behaving according to its current intended design Area-CodeFix Bug in code fixer help wanted The issue is up-for-grabs, and can be claimed by commenting good first issue 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-CodeFix Bug in code fixer Bug The product is not behaving according to its current intended design good first issue help wanted The issue is up-for-grabs, and can be claimed by commenting
Projects
None yet
2 participants