diff options
Diffstat (limited to 'tests/openarray/topenarray.nim')
-rw-r--r-- | tests/openarray/topenarray.nim | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/tests/openarray/topenarray.nim b/tests/openarray/topenarray.nim index 0b6e3afc4..25b983651 100644 --- a/tests/openarray/topenarray.nim +++ b/tests/openarray/topenarray.nim @@ -23,5 +23,66 @@ proc main = when defined(js): discard # xxx bug #15952: `a` left unchanged else: doAssert a == [1, 0, 10, 20, 5] + block: # bug #12521 + block: + type slice[T] = openArray[T] + + # Proc using that alias + proc testing(sl: slice[int]): seq[int] = + for item in sl: + result.add item + + let mySeq = @[1, 2, 3, 4, 5, 6, 7, 8, 9] + doAssert testing(mySeq) == mySeq + doAssert testing(mySeq[2..^2]) == mySeq[2..^2] + + block: + type slice = openArray[int] + + # Proc using that alias + proc testing(sl: slice): seq[int] = + for item in sl: + result.add item + + let mySeq = @[1, 2, 3, 4, 5, 6, 7, 8, 9] + doAssert testing(mySeq) == mySeq + doAssert testing(mySeq[2..^2]) == mySeq[2..^2] + + block: # bug #23321 + block: + proc foo(x: openArray[int]) = + doAssert x[0] == 0 + + var d = new array[1, int] + foo d[].toOpenArray(0, 0) + + block: + proc foo(x: openArray[int]) = + doAssert x[0] == 0 + + proc task(x: var array[1, int]): var array[1, int] = + result = x + var d: array[1, int] + foo task(d).toOpenArray(0, 0) + + block: + proc foo(x: openArray[int]) = + doAssert x[0] == 0 + + proc task(x: var array[1, int]): lent array[1, int] = + result = x + var d: array[1, int] + foo task(d).toOpenArray(0, 0) + + block: + proc foo(x: openArray[int]) = + doAssert x[0] == 0 + + proc task(x: var array[1, int]): ptr array[1, int] = + result = addr x + var d: array[1, int] + foo task(d)[].toOpenArray(0, 0) + + main() -# static: main() # xxx bug #15952: Error: cannot generate code for: mSlice +static: main() |