Skip to content

[Bug]: Compilation error on set types that implement both IReadonlySet and ISet #4406

@guythetechie

Description

@guythetechie

Description

I cannot write assertions directly on System.Collections.Immutable.ImmutableHashSet<T>, which implements both IReadonlySet<T> and ISet<T>. Workaround is to cast it as one of those types first.

This was working in version 1.7.20.

Expected Behavior

I expected the code to compile.

Actual Behavior

It gives this error:

The call is ambiguous between the following methods or properties: 'TUnit.Assertions.Assert.That<TItem>(System.Collections.Generic.IReadOnlySet<TItem>?, string?)' and 'TUnit.Assertions.Assert.That<TItem>(System.Collections.Generic.ISet<TItem>?, string?)'

Steps to Reproduce

Minimal reproduction code:

[Test]
public async Task Set_is_empty()
{
    var set = ImmutableHashSet<int>.Empty;
    await Assert.That(set).IsEmpty();
}

TUnit Version

1.11.8

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

dotnet CLI (dotnet test / dotnet run)

Error Output / Stack Trace

Additional Context

No response

IDE-Specific Issue?

  • I've confirmed this issue occurs when running via dotnet test or dotnet run, not just in my IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions