Skip to content

IDE0025 code fixer changes semantics and sometimes suggests invalid code. #77473

@franchyd

Description

@franchyd

Version Used:
Compiler version: '4.13.0-3.25112.7 (afe5bc4)'. Language version: preview.
Steps to Reproduce:

public class Program
{
    public static object obj
    {
        get
        {
            return field;
        }
    } = new();
    public static object fixed_obj => field = new(); // New semantics (reassign on every get)
    public static object? nullable_obj
    {
        get
        {
            return field ?? new();
        }
    } = new();
    public static object? fixed_nullable_obj => field ?? new() = new(); // CS0131
}

Diagnostic Id:

IDE0025 Use expression body for properties

Expected Behavior:

Code fixer not suggested when property has an initializer

Actual Behavior:
Code fixer suggested and applies change semantics and possibly invalid code.

Metadata

Metadata

Labels

Area-IDEFeature - IDE0025Use expression body for propertieshelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

Type

Projects

Status

Completed

Relationships

None yet

Development

No branches or pull requests

Issue actions