summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-03-05 16:02:34 +0100
committerGitHub <noreply@github.com>2020-03-05 16:02:34 +0100
commit83e715c5b6b2501c02459398a2f394c457758a55 (patch)
tree2855c11dba5742de851dab4935881e03467b49ed /compiler
parent62c113ebc7ba6fa1594b24158a6cc3e1170f4030 (diff)
downloadNim-83e715c5b6b2501c02459398a2f394c457758a55.tar.gz
fixes #5170 (#13589)
* fixes #5170

* make tests green
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semstmts.nim2
-rw-r--r--compiler/sighashes.nim19
2 files changed, 11 insertions, 10 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 4d4f70245..b91e93025 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -1298,6 +1298,8 @@ proc typeSectionFinalPass(c: PContext, n: PNode) =
         checkConstructedType(c.config, s.info, s.typ)
         if s.typ.kind in {tyObject, tyTuple} and not s.typ.n.isNil:
           checkForMetaFields(c, s.typ.n)
+          # fix bug #5170: ensure locally scoped object types get a unique name:
+          if s.typ.kind == tyObject and not isTopLevel(c): incl(s.flags, sfGenSym)
   #instAllTypeBoundOp(c, n.info)
 
 
diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim
index f94cd5bce..0902a839b 100644
--- a/compiler/sighashes.nim
+++ b/compiler/sighashes.nim
@@ -35,6 +35,7 @@ type
     CoIgnoreRange
     CoConsiderOwned
     CoDistinct
+    CoHashTypeInsideNode
 
 proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag])
 
@@ -61,7 +62,7 @@ proc hashTypeSym(c: var MD5Context, s: PSym) =
       c &= "."
       it = it.owner
 
-proc hashTree(c: var MD5Context, n: PNode) =
+proc hashTree(c: var MD5Context, n: PNode; flags: set[ConsiderFlag]) =
   if n == nil:
     c &= "\255"
     return
@@ -75,6 +76,8 @@ proc hashTree(c: var MD5Context, n: PNode) =
     c &= n.ident.s
   of nkSym:
     hashSym(c, n.sym)
+    if CoHashTypeInsideNode in flags and n.sym.typ != nil:
+      hashType(c, n.sym.typ, flags)
   of nkCharLit..nkUInt64Lit:
     let v = n.intVal
     lowlevel v
@@ -84,7 +87,7 @@ proc hashTree(c: var MD5Context, n: PNode) =
   of nkStrLit..nkTripleStrLit:
     c &= n.strVal
   else:
-    for i in 0..<n.len: hashTree(c, n[i])
+    for i in 0..<n.len: hashTree(c, n[i], flags)
 
 proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
   if t == nil:
@@ -155,11 +158,7 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
           let oldFlags = t.sym.flags
           # Mild hack to prevent endless recursion.
           t.sym.flags = t.sym.flags - {sfAnon, sfGenSym}
-          for n in t.n:
-            assert(n.kind == nkSym)
-            let s = n.sym
-            c.hashSym s
-            c.hashType s.typ, flags
+          hashTree(c, t.n, flags + {CoHashTypeInsideNode})
           t.sym.flags = oldFlags
         else:
           # The object has no fields: we _must_ add something here in order to
@@ -176,7 +175,7 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
     if tfVarIsPtr in t.flags: c &= ".varisptr"
   of tyFromExpr:
     c &= char(t.kind)
-    c.hashTree(t.n)
+    c.hashTree(t.n, {})
   of tyTuple:
     c &= char(t.kind)
     if t.n != nil and CoType notin flags:
@@ -192,11 +191,11 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
   of tyRange:
     if CoIgnoreRange notin flags:
       c &= char(t.kind)
-      c.hashTree(t.n)
+      c.hashTree(t.n, {})
     c.hashType(t[0], flags)
   of tyStatic:
     c &= char(t.kind)
-    c.hashTree(t.n)
+    c.hashTree(t.n, {})
     c.hashType(t[0], flags)
   of tyProc:
     c &= char(t.kind)