summary refs log tree commit diff stats
path: root/tests/openarray/topenarray.nim
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2024-04-29 22:58:33 +0800
committerGitHub <noreply@github.com>2024-04-29 16:58:33 +0200
commitd09c3c0f58eb9f1f4cf07fa98a9686aa19778f16 (patch)
tree6c363660e5a66a589630daafe43d94d87420a828 /tests/openarray/topenarray.nim
parent47594eb9091e788e672c1020f18d84a54bdcbf37 (diff)
downloadNim-d09c3c0f58eb9f1f4cf07fa98a9686aa19778f16.tar.gz
fixes #23321; Error: internal error: openArrayLoc: ref array[0..0, int] (#23548)
fixes #23321

In the function `mapType`, ptrs (tyPtr, tyVar, tyLent, tyRef)
are mapped into ctPtrToArray, the dereference of which is skipped
in the `genref`. We need to skip these ptrs in the function
`genOpenArraySlice`.
Diffstat (limited to 'tests/openarray/topenarray.nim')
-rw-r--r--tests/openarray/topenarray.nim35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/openarray/topenarray.nim b/tests/openarray/topenarray.nim
index c752becf2..25b983651 100644
--- a/tests/openarray/topenarray.nim
+++ b/tests/openarray/topenarray.nim
@@ -48,6 +48,41 @@ proc main =
       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()