Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

followup #17001: improve coverage for tests/openarray/topenarray.nim #17006

Merged
merged 2 commits into from
Feb 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions tests/openarray/topenarray.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@ discard """
targets: "c cpp js"
"""

proc pro[T](a: var openArray[T]) = discard
proc fn1[T](a: openArray[T]): seq[T] =
for ai in a: result.add ai

proc fn2[T](a: var openArray[T]): seq[T] =
for ai in a: result.add ai

proc fn3[T](a: var openArray[T]) =
for i, ai in mpairs(a): ai = i * 10

proc main =
var a = [1,2,3,4,5]

pro(toOpenArray(a, 1, 3))
pro(a.toOpenArray(1,3))
doAssert fn1(a.toOpenArray(1,3)) == @[2,3,4]

doAssert fn2(toOpenArray(a, 1, 3)) == @[2,3,4]
doAssert fn2(a.toOpenArray(1,3)) == @[2,3,4]

fn3(a.toOpenArray(1,3))
when defined(js): discard # xxx bug #15952: `a` left unchanged
else: doAssert a == [1, 0, 10, 20, 5]

main()
# static: main() # xxx bug #15952: Error: cannot generate code for: mSlice