Skip to content

Delegate parameter default values should affect lambda parameter initial state #48844

@RikkiGibson

Description

@RikkiGibson

Version Used: d5931e0

Steps to Reproduce:

#nullable enable

public delegate void Del<T>(T t = default);

public class C<T>
{
    public void M0(T t) { }

    // Behavior for member methods, for comparison
    public void M1(T t = default)
    {
        M0(t); // warning CS8604: Possible null reference argument
    }
    
    public void M2()
    {
        Del<T> del = t => M0(t); // expected warning, but didn't get one
        Del<T> del1 = t => { t = default; M0(t); }; // warning CS8604: Possible null reference argument
    }
}

SharpLab

Expected Behavior: Warnings on all 3 commented lines

Actual Behavior: Warnings on 2 commented lines

I might be able to fix this with my "put parameter default values in the bound tree" work. Not yet sure.

edit: Expected behavior of this scenario has changed based on the proposal nullable-parameter-default-value-analysis.md

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions