-
Notifications
You must be signed in to change notification settings - Fork 4.1k
[C#] Slicing a previously sliced array computes an incorrect offset #40792
Copy link
Copy link
Closed
Description
Describe the bug, including details regarding any error messages, version, and platform.
Test to reproduce:
[Fact]
public void RecursiveArraySlice()
{
var initialValues = Enumerable.Range(0, 100).ToArray();
var array = new Int32Array.Builder().AppendRange(initialValues).Build();
var sliced = (Int32Array) array.Slice(20, 30);
var slicedAgain = (Int32Array) sliced.Slice(5, 10);
Assert.Equal(25, slicedAgain.Offset); // Fails with "Actual: 45"
Assert.Equal(10, slicedAgain.Length);
Assert.Equal(
initialValues.Skip(25).Take(10).Select(val => (int?) val).ToArray(),
(IReadOnlyList<int?>) slicedAgain);
}This is because the current offset is accounted for twice, first at
| offset += array.Data.Offset; |
Then again at
| offset += Offset; |
This only works if the offset is zero.
Component(s)
C#
Reactions are currently unavailable