summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-07-16 12:07:06 +0200
committerGitHub <noreply@github.com>2020-07-16 12:07:06 +0200
commit6b607413e90111f74dd77c1fa31ba5f183f72bdf (patch)
tree4b7e77dff4e54bcf088155f9d70d00b5dd6542f7
parentba5604b96d7d2604a02b4f8ac8b67c54ea92ecfa (diff)
downloadNim-6b607413e90111f74dd77c1fa31ba5f183f72bdf.tar.gz
cursor inference: hotfix (#14999)
-rw-r--r--compiler/cursor_inference.nim21
1 files changed, 13 insertions, 8 deletions
diff --git a/compiler/cursor_inference.nim b/compiler/cursor_inference.nim
index e0999b5be..224131270 100644
--- a/compiler/cursor_inference.nim
+++ b/compiler/cursor_inference.nim
@@ -35,6 +35,7 @@ type
     mutations: IntSet
     reassigns: IntSet
     config: ConfigRef
+    inAsgnSource: int
 
 proc locationRoot(e: PNode; followDotExpr = true): PSym =
   var n = e
@@ -221,7 +222,9 @@ proc analyse(c: var Con; n: PNode) =
 
   of nkAsgn, nkFastAsgn:
     analyse(c, n[0])
+    inc c.inAsgnSource
     analyse(c, n[1])
+    dec c.inAsgnSource
 
     if n[0].kind == nkSym:
       if hasDestructor(n[0].typ):
@@ -252,14 +255,16 @@ proc analyse(c: var Con; n: PNode) =
       c.mutations.incl r.id
 
   of nkTupleConstr, nkBracket, nkObjConstr:
-    for i in ord(n.kind == nkObjConstr)..<n.len:
-      if n[i].kind == nkSym:
-        # we assume constructions with cursors are better without
-        # the cursors because it's likely we can move then, see
-        # test arc/topt_no_cursor.nim
-        let r = n[i].sym
-        c.mayOwnData.incl r.id
-        c.mutations.incl r.id
+    for child in n: analyse(c, child)
+    if c.inAsgnSource > 0:
+      for i in ord(n.kind == nkObjConstr)..<n.len:
+        if n[i].kind == nkSym:
+          # we assume constructions with cursors are better without
+          # the cursors because it's likely we can move then, see
+          # test arc/topt_no_cursor.nim
+          let r = n[i].sym
+          c.mayOwnData.incl r.id
+          c.mutations.incl r.id
 
   of nkVarSection, nkLetSection:
     for it in n: