Skip to content

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

@OswaldHurlem

Description

@OswaldHurlem

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

  • CommunityToolkit.Common
  • CommunityToolkit.Diagnostics
  • CommunityToolkit.HighPerformance
  • CommunityToolkit.Mvvm (aka MVVM Toolkit)

Nuget package version(s)

8.1.0

Additional context

No response

Help us help you

No, just wanted to report this

Metadata

Metadata

Assignees

No one assigned

    Labels

    by designSome behavior that is intended and not an issuehigh-performance 🚂Issues/PRs for the HighPerformance package

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions