diff --git a/Src/IronPython/Runtime/Operations/ArrayOps.cs b/Src/IronPython/Runtime/Operations/ArrayOps.cs index 0247f68e5..e68e42d76 100644 --- a/Src/IronPython/Runtime/Operations/ArrayOps.cs +++ b/Src/IronPython/Runtime/Operations/ArrayOps.cs @@ -495,7 +495,7 @@ private static void FixSlice(Slice slice, Array a, out int ostart, out int ostop if (ostop < 0 && lb >= 0) { ostop += ub + 1; } - if (ostop < 0) { + if (ostop < lb) { ostop = ostep > 0 ? lb : lb - 1; } } else if (ostop > ub) { diff --git a/Tests/test_array.py b/Tests/test_array.py index d771a17dc..ccf9148e5 100644 --- a/Tests/test_array.py +++ b/Tests/test_array.py @@ -497,4 +497,20 @@ def test_equality_rank(self): self.assertTrue(c != d) self.assertFalse(d != d1) + def test_slice_down(self): + #arr = System.Array[int]((2, 3, 4), base=2) + arr = System.Array.CreateInstance(int, (3,), (2,)) + for i in range(2, 2 + 3): + arr[i] = i + + self.assertEqual(arr[-1:-4:-1], System.Array[int]((4, 3, 2))) + self.assertEqual(arr[-1:-5:-1], System.Array[int]((4, 3, 2))) + self.assertEqual(arr[-1:-6:-1], System.Array[int]((4, 3, 2))) + + self.assertEqual(arr[2:1:-1], System.Array[int]((2,))) + self.assertEqual(arr[2:-5:-1], System.Array[int]((2,))) + self.assertEqual(arr[2:-6:-1], System.Array[int]((2,))) + self.assertEqual(arr[1:-5:-1], System.Array[int](())) + self.assertEqual(arr[0:-5:-1], System.Array[int](())) + run_test(__name__)