CommunityToolkit / dotnet

.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
https://docs.microsoft.com/dotnet/communitytoolkit/?WT.mc_id=dotnet-0000-bramin
Other
2.99k stars 294 forks source link

Span2D<int>.Empty[0..0,0..0] and similar cases throw ArgumentOutOfRangeException #673

Closed OswaldHurlem closed 1 year ago

OswaldHurlem commented 1 year ago

Describe the bug

The indexer function Span2D<T>.Item[Range row, Range column] is similar to Span<T>.Item[Range range]. However, the latter returns an empty span when range's Start and End both equal the length of the span. The same is not true for the former's row and column arguments.

Regression

Not a regression

Steps to reproduce

These lines of code cause an ArgumentOutOfRangeException to be thrown:

var cornerOfEmptySpan2d = Span2D<int>.Empty[0..0,0..0];
var cornerOfSingleItemSpan2d = (new Span2D<int>(new[,] {{0}}))[1..1,1..1];

Whereas these do not:

var endOfEmptySpan = Span<int>.Empty[0..0];
var endOfSingleItemSpan = (new Span<int>(new[] {0}))[1..1];

Expected behavior

Span2D<int>.Empty[0..0,0..0] and (new Span2D<int>(new[,] {{0}}))[1..1,1..1] should return an empty Span2D.

Screenshots

No response

IDE and version

VS 2019

IDE version

No response

Nuget packages

Nuget package version(s)

8.1.0

Additional context

No response

Help us help you

No, just wanted to report this

OswaldHurlem commented 1 year ago

Appreciated 👍