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 #72334

Closed
just-ero opened this issue Feb 29, 2024 · 1 comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@just-ero
Copy link

Version Used

  • Compiler version: 4.10.0-2.24102.11 (b14dc4d)
  • 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)
    { }
}
@CyrusNajmabadi
Copy link
Member

Can you please move this to Roslyn-anayzers? GitHub is not letting me do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants