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

[Bug]: Extract to static readonly field code fix does not generate required field #7216

Open
just-ero opened this issue Feb 29, 2024 · 0 comments · May be fixed by #7231
Open

[Bug]: Extract to static readonly field code fix does not generate required field #7216

just-ero opened this issue Feb 29, 2024 · 0 comments · May be fixed by #7231

Comments

@just-ero
Copy link

Version Used

  • Compiler version: 4.10.0-2.24102.11 (b14dc4dc)
  • VSCode: 1.87.0, 019f4d1419fbc8219a181fab7892ebccf7ee29a2, x64
  • C# extension: v2.18.16, C# Dev Kit Extension: v1.3.10

Steps to Reproduce

  1. Open or create any C# project in Visual Studio Code.
  2. class Class1(int[] arr);
    
    class Class2 : Class1
    {
        public Class2()
            : base(new int[] { 1, 2, 3 })
        { }
    }
  3. Suggestion CA1861 will appear on the new int[] { 1, 2, 3 } argument in Class2's call to the base constructor.
  4. Attempt to apply the suggested fix.

Expected Behavior

The suggested static readonly field is generated and the argument is replaced with the field's name:

class Class2 : Class1
{
    private static readonly int[] arr = new int[] { 1, 2, 3 }; // Should respect any applying naming rules.

    public Class2()
        : base(arr)
    { }
}

Actual Behavior

The field is not generated. The argument is replaced with the parameter name:

class Class2 : Class1
{
    public Class2()
        : base(arr)
    { }
}

Moved from dotnet/roslyn#72334.

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

Successfully merging a pull request may close this issue.

1 participant