-
Notifications
You must be signed in to change notification settings - Fork 380
Wrong height and width of empty spans obtained from Span<T>.AsSpan2D. #1101
Copy link
Copy link
Closed
Labels
bug 🐛An unexpected issue that highlights incorrect behaviorAn unexpected issue that highlights incorrect behavior
Description
Describe the bug
Two-dimensional spans like Span<T>.Empty.AsSpan2D(n, 0) and Span<T>.Empty.AsSpan2D(0, n) always have Height = 0 and Width = 0. This is caused by the special case https://github.com/CommunityToolkit/dotnet/blob/main/src/CommunityToolkit.HighPerformance/Memory/Span2D%7BT%7D.cs#L534.
Regression
No response
Steps to reproduce
// Examples of unexpected behavior:
Console.WriteLine(Span<bool>.Empty.AsSpan2D(1, 0).Height); // Prints 0.
Console.WriteLine(Span<bool>.Empty.AsSpan2D(0, 1).Width); // Prints 0.
// Examples of expected behavior:
Console.WriteLine(new bool[1, 0].AsSpan2D().Height); // Prints 1.
Console.WriteLine(new bool[0, 1].AsSpan2D().Width); // Prints 1.
Expected behavior
I expect Span<T>.Empty.AsSpan2D(n, 0) to have Height = n and Span<T>.Empty.AsSpan2D(0, n) to have Width = n. This is the behavior for two-dimensional arrays, i.e. new T[n, 0].AsSpan2D() and new T[0, n].AsSpan2D() have the correct widths and heights.
Screenshots
No response
IDE and version
Rider
IDE version
No response
Nuget packages
- CommunityToolkit.Common
- CommunityToolkit.Diagnostics
- CommunityToolkit.HighPerformance
- CommunityToolkit.Mvvm (aka MVVM Toolkit)
Nuget package version(s)
8.4.0
Additional context
No response
Help us help you
No, just wanted to report this
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bug 🐛An unexpected issue that highlights incorrect behaviorAn unexpected issue that highlights incorrect behavior