Open
Description
Version Used:
Visual Studio 2022 Community Edition, 17.14.0 Preview 4.0
.NET 9
Steps to Reproduce:
public sealed class Utf8String
{
public static implicit operator Utf8String(ReadOnlySpan<byte> data)
{
return new();
}
}
internal sealed class CustomBinaryWriter() : BinaryWriter()
{
public sealed override void Write(byte[] buffer)
{
Console.WriteLine("Latest Language Version");
}
public void Write(Utf8String utf8String)
{
Console.WriteLine("Preview Language Version");
}
}
internal static class Program
{
static void Main()
{
byte[] buffer = new byte[10];
CustomBinaryWriter writer = new();
writer.Write(buffer);
}
}
I'd speculate that this is caused by first class span, but I did no internal investigation of the compiler.
Expected Behavior:
The compiler should decide that Write(byte[])
is the better overload because it has an exact type match.
Actual Behavior:
byte[]
is implicitly converted to ReadOnlySpan<byte>
and then to Utf8String
, so Write(Utf8String)
is chosen.