This commit is contained in:
Andreas Rumpf
2017-11-02 22:09:58 +01:00
parent cccdd9b58e
commit 0f5261e971
2 changed files with 9 additions and 3 deletions

View File

@@ -3493,14 +3493,14 @@ proc `[]`*[Idx, T, U, V](a: array[Idx, T], x: HSlice[U, V]): seq[T] =
let xa = a ^^ x.a
let L = (a ^^ x.b) - xa + 1
result = newSeq[T](L)
for i in 0..<L: result[i] = a[Idx(i + xa + int low(a))]
for i in 0..<L: result[i] = a[Idx(i + xa)]
proc `[]=`*[Idx, T, U, V](a: var array[Idx, T], x: HSlice[U, V], b: openArray[T]) =
## slice assignment for arrays.
let xa = a ^^ x.a
let L = (a ^^ x.b) - xa + 1
if L == b.len:
for i in 0..<L: a[Idx(i + xa + int low(a))] = b[i]
for i in 0..<L: a[Idx(i + xa)] = b[i]
else:
sysFatal(RangeError, "different lengths for slice assignment")

View File

@@ -4,7 +4,8 @@ discard """
3
@[(Field0: 1, Field1: 2), (Field0: 3, Field1: 5)]
2
@[a, new one, c]'''
@[a, new one, c]
@[1, 2, 3]'''
"""
proc foo[T](x, y: T): T = x
@@ -35,3 +36,8 @@ useOpenarray([1, 2, 3])
var z = @["a", "b", "c"]
mutOpenarray(z)
echo z
# bug #6675
var y: array[1..5, int] = [1,2,3,4,5]
y[3..5] = [1, 2, 3]
echo y[3..5]