Skip to content

Commit 999a4bb

Browse files
ringaboutnarimiran
authored andcommitted
closes #19969; add testcase for #19969 #15952 #16306 (#20610)
closes #19969; add testcase (cherry picked from commit 1db25ff)
1 parent 2292ff9 commit 999a4bb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/vm/topenarrays.nim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,31 @@ static:
3535
assert arr.toOpenArray(3, 4).toOpenArray(0, 0) == [1]
3636

3737

38+
# bug #19969
39+
proc f(): array[1, byte] =
40+
var a: array[1, byte]
41+
result[0..0] = a.toOpenArray(0, 0)
3842

43+
doAssert static(f()) == [byte(0)]
44+
45+
46+
# bug #15952
47+
proc main1[T](a: openArray[T]) = discard
48+
proc main2[T](a: var openArray[T]) = discard
49+
50+
proc main =
51+
var a = [1,2,3,4,5]
52+
main1(a.toOpenArray(1,3))
53+
main2(a.toOpenArray(1,3))
54+
static: main()
55+
main()
56+
57+
# bug #16306
58+
{.experimental: "views".}
59+
proc test(x: openArray[int]): tuple[id: int] =
60+
let y: openArray[int] = toOpenArray(x, 0, 2)
61+
result = (y[0],)
62+
template fn=
63+
doAssert test([0,1,2,3,4,5]).id == 0
64+
fn() # ok
65+
static: fn()

0 commit comments

Comments
 (0)