Skip to content

CS0592 for NotNullWhen on extension property #81543

@UniqeId6542

Description

@UniqeId6542

Version Used: VS 17.14.21 .NET 9.0.11 Preview language features (Also VS 18, .NET 10)

I have a custom error type where I use null to indicate success.

public static bool IsSuccess([NotNullWhen(false)] this MyErrorClass? info)
{
    return info is null;
}

With the new C# 14 features, I wanted to change this to a property.

extension(MyErrorClass? info)
{
    public bool IsSuccess
    {
        [NotNullWhen(false)] // CS0592 error here
        get => info is null;
    }
}

With the new extension properties, it is now possible to write a property that runs on a null object. So, null analysis should be updated to support this.

Expected Behavior:
Some way to tell the null analysis that the extended class is not null given some property return value.

Actual Behavior:
It is not possible to change from an extension method to an extension property while preserving the null analysis.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions