Skip to content

Nullability information is wrong for lambdas in certain situations #55254

Closed
@davidfowl

Description

@davidfowl

Version Used: Version 17.0.0 Preview 3.0 [31528.426.main]

Steps to Reproduce:

using System.Reflection;

var dump = static (string s, Delegate d) =>
{
    var mi = d.Method;

    var context = new NullabilityInfoContext();
    var info = context.Create(mi.GetParameters()[0]);
    return new
    {
        ReadState = info.ReadState.ToString(),
        WriteState = info.WriteState.ToString(),
        Type = info.Type.ToString(),
        ElementType = info.ElementType?.ToString()
    };
};

Console.WriteLine(dump("/", (string? name) => $"Inline lambda {name}"));
Console.WriteLine(dump("/o", (string? name) => { }));

Expected Behavior:

{ ReadState = Nullable, WriteState = Nullable, Type = System.String, ElementType =  }
{ ReadState = Nullable, WriteState = Nullable, Type = System.String, ElementType =  }

Actual Behavior:

{ ReadState = Unknown, WriteState = Unknown, Type = System.String, ElementType =  }
{ ReadState = Unknown, WriteState = Unknown, Type = System.String, ElementType =  }

cc @cston

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions