Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

IDE0306 code fixer produces invalid code (CS9215) #77174

Open
Sergio0694 opened this issue Feb 12, 2025 · 1 comment
Open

IDE0306 code fixer produces invalid code (CS9215) #77174

Sergio0694 opened this issue Feb 12, 2025 · 1 comment

Comments

@Sergio0694
Copy link
Contributor

Version Used: Compiler version: '4.13.0-3.25105.4 (400efa2)'. Language version: 13.0.

Steps to Reproduce:

  1. Create a new .NET 9 console project
  2. Paste this code:
_ = Test(new Dictionary<string, object>());

static Dictionary<string, object> Test(IReadOnlyDictionary<string, object> d)
{
    return new(d);
}

A minimal repro, with source-code provided, is ideal. Most compiler/language issues can be distilled into a snippet that can be pasted into sharplab.

Diagnostic Id: IDE0306, "Collection initialization can be simplified"

Expected Behavior:

I shouldn't be getting this warning here.

Actual Behavior:

I get the IDE0306 warning:

Image

Applying the code fixer produces invalid code:

Image

cc. @CyrusNajmabadi

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 12, 2025
@Sergio0694
Copy link
Contributor Author

I can also repro with Queue<T>:

Image

@deepakrathore33 deepakrathore33 added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 12, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants