diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-10-07 13:43:39 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-07 07:43:39 +0200 |
commit | efa64aa49b11e93461626e84b9f67b6185f26e1f (patch) | |
tree | 89ebc44e3dc1eb09947580ce5901f2aa65443c79 | |
parent | f111009e5dadceeab2fb076c968f8e18a5e495f8 (diff) | |
download | Nim-efa64aa49b11e93461626e84b9f67b6185f26e1f.tar.gz |
fixes #22787; marks `var section` in the loop as reassign preventing cursor (#22800)
fixes #22787 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r-- | compiler/varpartitions.nim | 4 | ||||
-rw-r--r-- | tests/arc/t22787.nim | 37 |
2 files changed, 41 insertions, 0 deletions
diff --git a/compiler/varpartitions.nim b/compiler/varpartitions.nim index 74bf63da8..957497bb6 100644 --- a/compiler/varpartitions.nim +++ b/compiler/varpartitions.nim @@ -823,6 +823,10 @@ proc computeLiveRanges(c: var Partitions; n: PNode) = registerVariable(c, child[i]) #deps(c, child[i], last) + if c.inLoop > 0 and child[0].kind == nkSym: # bug #22787 + let vid = variableId(c, child[0].sym) + if child[^1].kind != nkEmpty: + markAsReassigned(c, vid) of nkAsgn, nkFastAsgn, nkSinkAsgn: computeLiveRanges(c, n[0]) computeLiveRanges(c, n[1]) diff --git a/tests/arc/t22787.nim b/tests/arc/t22787.nim new file mode 100644 index 000000000..5840a984b --- /dev/null +++ b/tests/arc/t22787.nim @@ -0,0 +1,37 @@ +discard """ + joinable: false +""" + +import std/assertions + +proc foo = + var s:seq[string] + var res = "" + + for i in 0..3: + s.add ("test" & $i) + s.add ("test" & $i) + + var lastname:string + + for i in s: + var name = i[0..4] + + if name != lastname: + res.add "NEW:" & name & "\n" + else: + res.add name & ">" & lastname & "\n" + + lastname = name + + doAssert res == """ +NEW:test0 +test0>test0 +NEW:test1 +test1>test1 +NEW:test2 +test2>test2 +NEW:test3 +test3>test3 +""" +foo() \ No newline at end of file |