Skip to content

Passing non-null string to nullable ref argument should not warn #26739

@jcouv

Description

@jcouv

This warning is surprising.

public class C 
{
    public void M() 
    {
        string? s = "";
        M(ref s);  // warning CS8600: Converting null literal or possible null value to non-nullable type.
    }
    void M(ref string? s) => throw null;
}

Note: this is also a scenario where we think a special attribute could make sense (this method never sets the ref parameter to null).

Tagging @cston

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions