Skip to content

[Bug]: Overload resolution on string members prefers equality of IEnumerable<char> over string #5702

@Ilia-Kosenkov

Description

@Ilia-Kosenkov

Description

I stumbled upon this issue while adopting TUnit. If I am asserting an object to have a member of type string equal to something, using .Member() syntax for chaining, the overload resolution fails to pick up string comparison, favouring IEnumerable<char>. This triggers TUnitAssrtions0016 warning.

Image

Expected Behavior

.IsEqualTo<string>(string) is preferred over .IsEqualTo<IEnumerable<char>>()

Actual Behavior

The opposite happens, which forces us to spell out .IsEuqualTo<string>(expectation).
This, however, does not happen with plain asserts over strings, e.g.

await Assert.That(@string).IsEqualTo(expectation);

correctly uses string overload.

Steps to Reproduce

var value = KeyValuePair.Create<string, object?>("error", null);

await Assert.That(value).Member(kvp => kvp.Key, key => key.IsEqualTo("error"));

TUnit Version

1.37.36

.NET Version

.NET 10

Operating System

Windows

IDE / Test Runner

JetBrains Rider

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