roslynator icon indicating copy to clipboard operation
roslynator copied to clipboard

Collection expressions are not considered "obvious" typing

Open RenderMichael opened this issue 1 year ago • 1 comments
trafficstars

Product and Version Used:

4.10.0

Steps to Reproduce:

roslynator_object_creation_type_style = implicit_when_type_is_obvious

roslynator_array_creation_type_style = implicit_when_type_is_obvious
List<string> strings = [
    "1", "2", "3"
    ]; // RCS1250

var x = new HasArray
{
    Strings = [], // RCS1250 *and* RCS1014
};

internal class HasArray
{
    public required string[] Strings { get; set; }
}

Actual Behavior: RCS1250: Use explicit object creation RCS1014: Use explicitly typed array

Expected Behavior: As of C#12, there is no natural type for collection expressions, it's always target-type, and as such the type is always "obvious"

RenderMichael avatar Feb 16 '24 16:02 RenderMichael