Upcoming C# 14 breaking change: first-class spans #3021
-
Hey xUnit folks, your friendly neighborhood C# LDM member here. I wanted to let you know that a feature we're planning for C# 14, first-class spans, is going to introduce a new source-breaking change for Ambiguous todaystring[] str = ["hello"];
Assert.Equal(["hello"], str); // error CS0121: The call is ambiguous between the following methods or properties: 'Assert.Equal<T>(T[], T[])' and 'Assert.Equal<T>(ReadOnlySpan<T>, Span<T>)'
// This one is more of an edge case, but is also an error
long[] l = [1];
Assert.Equal<long>([2], l); // error CS0121: The call is ambiguous between the following methods or properties: 'Assert.Equal<T>(T[], T[])' and 'Assert.Equal<T>(ReadOnlySpan<T>, Span<T>)' Ambiguous in C# 14var x = new long[] { 1 };
Assert.Equal([2], x); // previously Assert.Equal<T>(T[], T[]), now ambiguous with Assert.Equal<T>(ReadOnlySpan<T>, Span<T>) We've documented these ambiguities as part of the feature specification here, and discussed them during this LDM. To sum up, we see a couple of options available for fixing these potential ambiguities:
Just wanted to give you a heads up so you could look at this now, rather than after C# 14 releases. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
I am seeing build errors in aspnetcore even with the new version (2.9.2). Some of these appear when comparing |
Beta Was this translation helpful? Give feedback.
I opted to add the extra overload, because polyfilling
OverloadResolutionPriority
would still require a fairly new compiler to be effective.Available in v2
2.9.1-pre.11
Available in v3
0.4.0-pre.3
https://xunit.net/docs/using-ci-builds