Skip to content

Interface deriving from IEquatable<T> twice triggers CS8620 on wrong interface #36018

@drewnoakes

Description

@drewnoakes

Version Used: VS 16.2.0-pre.1.0+28917.182

Steps to Reproduce:

#nullable enable

interface IEquatable<T> {
  bool Equals(T other);    
}

interface IFoo : IEquatable<IFoo?>, IEquatable<string?>
{ }

class Foo : IFoo
{
    public bool Equals(string? other)
    {
        return true;
    }

    public bool Equals(IFoo? other)
    {
        return true;
    }
}

class C
{
    void M(IFoo foo)
    {
        foo.Equals("");
        //         ^^ CS8620
        // Argument of type 'string' cannot be used for parameter 'other' of type 'IFoo'
        // in 'bool IEquatable<IFoo?>.Equals(IFoo? other)' due to differences in the
        // nullability of reference types.
    }
}

The error message implies an incorrect overload of IEquatable<>.Equals is being considered when evaluating nullability here.

Expected Behavior:

No warning.

Actual Behavior:

CS8620 is issued.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions