fixes #19457 seqs are not properly updated in loop with ARC/ORC (#19922)

* test CI

* fixes #19457

* add comments

Co-authored-by: sandytypical <43030857+xflywind@users.noreply.github.com>
This commit is contained in:
ringabout 2022-09-28 19:12:08 +08:00 • committed by GitHub
commit fe8feb46c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 15 deletions

16
tests/arc/t19457.nim Normal file
View file

@ -0,0 +1,16 @@
discard """
matrix: "--gc:refc; --gc:arc"
"""
# bug #19457
proc gcd(x, y: seq[int]): seq[int] =
var
a = x
b = y
while b[0] > 0:
let c = @[a[0] mod b[0]]
a = b
b = c
return a
doAssert gcd(@[1], @[2]) == @[1]

View file

@ -5,21 +5,28 @@ discard """
var
it_cursor
jt_cursor
it_cursor = root
block :tmp:
while (
not (it_cursor == nil)):
echo [it_cursor.s]
it_cursor = it_cursor.ri
jt_cursor = root
block :tmp_1:
while (
not (jt_cursor == nil)):
var ri_1_cursor
ri_1_cursor = jt_cursor.ri
echo [jt_cursor.s]
jt_cursor = ri_1_cursor
jt
try:
it_cursor = root
block :tmp:
while (
not (it_cursor == nil)):
echo [it_cursor.s]
it_cursor = it_cursor.ri
`=copy`(jt, root)
block :tmp_1:
while (
not (jt == nil)):
var ri_1
try:
`=copy`(ri_1, jt.ri)
echo [jt.s]
`=sink`(jt, ri_1)
wasMoved(ri_1)
finally:
`=destroy`(ri_1)
finally:
`=destroy`(jt)
-- end of expandArc ------------------------'''
"""