Skip to content

RCS1250 not detecting an obvious type situation #1202

Description

@eduardomezencio

Product and Version Used: Roslynator.Analyzers 4.5.0, dotnet 7

Steps to Reproduce:
Consider that configuration is roslynator_object_creation_type_style = implicit_when_type_is_obvious.
In the following code:

// SomeType can be simply `public record SomeType;`
public record MyRecord(SomeType? Whatever = null)
{
    public SomeType Whatever { get; init; } = Whatever ?? new();
}

The new() gives RCS1250: Use explicit object creation. The example below behaves as expected, wihout raising the problem:

public record MyRecord
{
    public SomeType Whatever { get; init; } = new();
}

Actual Behavior: It raises the error in a situation where the type is obvious (considering that in my second example the new is considered obvious, the first is basically the same situation)

Expected Behavior: Not raising RCS1250 in my first example

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions