Skip to content

IDE0028 changes program behavior without notice #77416

@stephentoub

Description

@stephentoub

Version Used:
Version 17.14.0 Preview 2.0 [35828.13.main]

Steps to Reproduce:

using System.Collections.Concurrent;

ConcurrentQueue<int> queue = new ConcurrentQueue<int>();
BlockingCollection<int> bc = new(queue);
bc.Add(42);
Console.WriteLine(queue.Count);

Running that outputs 1. Then run the fixer, which changes the code to:

using System.Collections.Concurrent;

ConcurrentQueue<int> queue = new ConcurrentQueue<int>();
BlockingCollection<int> bc = [.. queue, 42];
Console.WriteLine(queue.Count);

and that outputs 0.

Diagnostic Id:
IDE0028

Expected Behavior:
Either a note in the fixer that program behavior might be changed meaningfully, ala what IDE0028 provides in other cases:
Image
or somehow not fire in the cases of ownership transfer semantics.

Actual Behavior:
Image

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