Skip to content

var nullability analysis regression #52925

@davidmilligan

Description

@davidmilligan

Version Used:
Microsoft.Net.Compilers 3.9.0

Steps to Reproduce:

#nullable enable

class C<T> where T : notnull
{
    void M(T initial, System.Func<T, T?> selector)
    {
        // ⚠ CS8600 Converting null literal or possible null value to non-nullable type.
        //                                                     ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
        for (var current = initial; current != null; current = selector(current))
        {
        }
    }
}

Expected Behavior:

No CS8600 warning

Actual Behavior:

CS8600 warning

Notes:
This code snippet previous compiled without warning on 3.8.0, so this appears to be a regression. It also only happens with the constraint T : notnull. T : class for example does not give the warning

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions