Skip to content

CS8620 when using compound overloaded operator with nullable value type known as non-null #40468

@drewnoakes

Description

@drewnoakes

Version Used: 16.5.0 Preview 2.0 [29614.18.master]

Steps to Reproduce:

#nullable enable

struct S
{
    public static S operator |(S s, int _) => s;
}

class Program
{
    void M()
    {
        S? s = null;

        s ??= new S();

        s.ToString(); // No warning

        s |= 321; // CS8620 
    }
}

Argument of type 'S?' cannot be used for parameter 's' of type 'S' in 'S S.operator |(S s, int _)' due to differences in the nullability of reference types.

Expected Behavior:

No warning.

Actual Behavior:

Warning.

The problem does not exist if you use the longer form:

s = s | 312;

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