summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/astalgo.nim3
-rw-r--r--compiler/lookups.nim36
-rw-r--r--compiler/semtypes.nim6
-rw-r--r--tests/errmsgs/t10251.nim12
4 files changed, 33 insertions, 24 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim
index 300089d81..5af8caad8 100644
--- a/compiler/astalgo.nim
+++ b/compiler/astalgo.nim
@@ -777,9 +777,10 @@ proc strTableInclReportConflict*(t: var TStrTable, n: PSym;
       replaceSlot = h
     h = nextTry(h, high(t.data))
   if replaceSlot >= 0:
+    result = t.data[replaceSlot] # found it
     if not onConflictKeepOld:
       t.data[replaceSlot] = n # overwrite it with newer definition!
-    return t.data[replaceSlot] # found it
+    return result
   elif mustRehash(t.data.len, t.counter):
     strTableEnlarge(t)
     strTableRawInsert(t.data, n)
diff --git a/compiler/lookups.nim b/compiler/lookups.nim
index a21e35ddc..9dac106e4 100644
--- a/compiler/lookups.nim
+++ b/compiler/lookups.nim
@@ -293,29 +293,28 @@ proc wrongRedefinition*(c: PContext; info: TLineInfo, s: string;
       "redefinition of '$1'; previous declaration here: $2" %
       [s, c.config $ conflictsWith])
 
-proc addDecl*(c: PContext, sym: PSym, info: TLineInfo) =
-  let conflict = c.currentScope.addUniqueSym(sym)
+proc addDeclAt*(c: PContext; scope: PScope, sym: PSym, info: TLineInfo) =
+  let conflict = scope.addUniqueSym(sym)
   if conflict != nil:
     wrongRedefinition(c, info, sym.name.s, conflict.info)
 
-proc addDecl*(c: PContext, sym: PSym) =
-  let conflict = strTableInclReportConflict(c.currentScope.symbols, sym, true)
-  if conflict != nil:
-    wrongRedefinition(c, sym.info, sym.name.s, conflict.info)
+proc addDeclAt*(c: PContext; scope: PScope, sym: PSym) {.inline.} =
+  addDeclAt(c, scope, sym, sym.info)
+
+proc addDecl*(c: PContext, sym: PSym, info: TLineInfo) {.inline.} =
+  addDeclAt(c, c.currentScope, sym, info)
+
+proc addDecl*(c: PContext, sym: PSym) {.inline.} =
+  addDeclAt(c, c.currentScope, sym)
 
 proc addPrelimDecl*(c: PContext, sym: PSym) =
   discard c.currentScope.addUniqueSym(sym)
 
-proc addDeclAt*(c: PContext; scope: PScope, sym: PSym) =
-  let conflict = scope.addUniqueSym(sym)
-  if conflict != nil:
-    wrongRedefinition(c, sym.info, sym.name.s, conflict.info)
-
 from ic / ic import addHidden
 
-proc addInterfaceDeclAux*(c: PContext, sym: PSym, forceExport = false) =
+proc addInterfaceDeclAux(c: PContext, sym: PSym) =
   ## adds symbol to the module for either private or public access.
-  if sfExported in sym.flags or forceExport:
+  if sfExported in sym.flags:
     # add to interface:
     if c.module != nil: exportSym(c, sym)
     else: internalError(c.config, sym.info, "addInterfaceDeclAux")
@@ -331,6 +330,10 @@ proc addInterfaceDeclAt*(c: PContext, scope: PScope, sym: PSym) =
     # adding into a non-shadow scope, we need to handle exports, etc
     addInterfaceDeclAux(c, sym)
 
+proc addInterfaceDecl*(c: PContext, sym: PSym) {.inline.} =
+  ## adds a decl and the interface if appropriate
+  addInterfaceDeclAt(c, c.currentScope, sym)
+
 proc addOverloadableSymAt*(c: PContext; scope: PScope, fn: PSym) =
   ## adds an symbol to the given scope, will check for and raise errors if it's
   ## a redefinition as opposed to an overload.
@@ -343,16 +346,11 @@ proc addOverloadableSymAt*(c: PContext; scope: PScope, fn: PSym) =
   else:
     scope.addSym(fn)
 
-proc addInterfaceDecl*(c: PContext, sym: PSym) =
-  ## adds a decl and the interface if appropriate
-  addDecl(c, sym)
-  if not c.currentScope.isShadowScope:
-    addInterfaceDeclAux(c, sym)
-
 proc addInterfaceOverloadableSymAt*(c: PContext, scope: PScope, sym: PSym) =
   ## adds an overloadable symbol on the scope and the interface if appropriate
   addOverloadableSymAt(c, scope, sym)
   if not scope.isShadowScope:
+    # adding into a non-shadow scope, we need to handle exports, etc
     addInterfaceDeclAux(c, sym)
 
 proc openShadowScope*(c: PContext) =
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 84556ca1a..38307a9ac 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -138,15 +138,13 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
       identToReplace[] = symNode
     if e.position == 0: hasNull = true
     if result.sym != nil and sfExported in result.sym.flags:
-      incl(e.flags, {sfUsed, sfExported})
-    if result.sym != nil and not isPure:
-      addInterfaceDeclAux(c, e, forceExport = sfExported in result.sym.flags)
+      e.flags.incl {sfUsed, sfExported}
 
     result.n.add symNode
     styleCheckDef(c.config, e)
     onDef(e.info, e)
     if sfGenSym notin e.flags:
-      if not isPure: addDecl(c, e)
+      if not isPure: addInterfaceDecl(c, e)
       else: declarePureEnumField(c, e)
     if isPure and (let conflict = strTableInclReportConflict(symbols, e); conflict != nil):
       wrongRedefinition(c, e.info, e.name.s, conflict.info)
diff --git a/tests/errmsgs/t10251.nim b/tests/errmsgs/t10251.nim
new file mode 100644
index 000000000..5ad373ba3
--- /dev/null
+++ b/tests/errmsgs/t10251.nim
@@ -0,0 +1,12 @@
+discard """
+errormsg: "redefinition of 'foo'; previous declaration here: t10251.nim(9, 9)"
+line: 11
+column: 9
+"""
+
+type
+    Enum1 = enum
+        foo, bar, baz
+    Enum2 = enum
+        foo, bar, baz
+