diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-07-05 17:21:57 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-05 11:21:57 +0200 |
commit | 145e002c74c4393b9ac71d5a8cfe066fbf38a048 (patch) | |
tree | 0077de57d031b4edf09938d052a68e37029db6e3 /tests/arc | |
parent | 86ff37fab8656f7acd08fc9c3fa237f9e022dbf4 (diff) | |
download | Nim-145e002c74c4393b9ac71d5a8cfe066fbf38a048.tar.gz |
fixes #22132; hoisted openArray params result in erroneous code (#22224)
Diffstat (limited to 'tests/arc')
-rw-r--r-- | tests/arc/topenarray.nim | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/arc/topenarray.nim b/tests/arc/topenarray.nim index 0e45f3ec7..67c512e4f 100644 --- a/tests/arc/topenarray.nim +++ b/tests/arc/topenarray.nim @@ -50,3 +50,21 @@ proc f(a: var string) = var a = "Hello" f(a) doAssert a == "Hallo" + +# bug #22132 +block: + func foo[T](arr: openArray[T], idx: int = arr.low): string = + doAssert idx == 0 + return $arr + + let bug = ["0", "c", "a"] + + let str = foo(bug) + + const expected = """["0", "c", "a"]""" + doAssert str == expected + + const noBugConst = ["0", "c", "a"] + doAssert foo(noBugConst) == expected + let noBugSeq = @["0", "c", "a"] + doAssert foo(noBugSeq) == expected |