Skip to content

IDE0028 incorrectly triggers for dictionary shallow cloning #82752

@barjonas

Description

@barjonas

Version Used:
From #error version: Compiler version: '5.5.0-2.26153.17 (68f89b7e2593bb313560a7b612739ae7f8ffd128)'. Language version: 14.0.

Steps to Reproduce:
(Minimal reproduction solution here)

  1. Create a new C# console project with a net10.0 target, <LangVersion>Preview</LangVersion>.
  2. Add the following code.
using System.Collections.Immutable;
Dictionary<int, ImmutableList<int>> original = new() { { 1, [1, 1] } };
Dictionary<int, ImmutableList<int>> shallowClone = new(original);
Console.WriteLine(shallowClone[1].Count);

Note the analyzer message: IDE0028 Collection initialization can be simplified
3. Apply the Codefix.
Note the buildable result: Dictionary<int, ImmutableList<int>> shallowClone = [with(original)];

Expected Behavior:
No analyzer result OR codefix that produces buildable code.

Actual Behavior:
Analyzer result with invalid codefix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions