summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-10-07 13:43:39 +0800
committerGitHub <noreply@github.com>2023-10-07 07:43:39 +0200
commitefa64aa49b11e93461626e84b9f67b6185f26e1f (patch)
tree89ebc44e3dc1eb09947580ce5901f2aa65443c79
parentf111009e5dadceeab2fb076c968f8e18a5e495f8 (diff)
downloadNim-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.nim4
-rw-r--r--tests/arc/t22787.nim37
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
8fdc852861ecd07c89256495ab'>286e5958d ^
053309e60 ^




286e5958d ^
053309e60 ^





286e5958d ^
053309e60 ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42