summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2014-11-20 21:02:51 +0100
committerAraq <rumpf_a@web.de>2014-11-20 21:02:51 +0100
commitbb532a697edad1bac60a87a7ff43956c9635973d (patch)
treeccdf1750dd76c17737096a0a19a46065fbef48e8 /compiler
parent3215666e33846db87e3b3ac1b6ab51a14f7b6912 (diff)
downloadNim-bb532a697edad1bac60a87a7ff43956c9635973d.tar.gz
fixes #1562, fixes #1543
Diffstat (limited to 'compiler')
-rw-r--r--compiler/astalgo.nim14
-rw-r--r--compiler/sem.nim2
-rw-r--r--compiler/semtypinst.nim2
3 files changed, 14 insertions, 4 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim
index 110b0c26e..e66158e8d 100644
--- a/compiler/astalgo.nim
+++ b/compiler/astalgo.nim
@@ -638,14 +638,22 @@ proc strTableIncl*(t: var TStrTable, n: PSym): bool {.discardable.} =
   # This way the newest redefinition is picked by the semantic analyses!
   assert n.name != nil
   var h: THash = n.name.h and high(t.data)
+  var replaceSlot = -1
   while true:
     var it = t.data[h]
     if it == nil: break
+    # Semantic checking can happen multiple times thanks to templates
+    # and overloading: (var x=@[]; x).mapIt(it).
+    # So it is possible the very same sym is added multiple
+    # times to the symbol table which we allow here with the 'it == n' check.
     if it.name.id == n.name.id and reallySameIdent(it.name.s, n.name.s):
-      t.data[h] = n           # overwrite it with newer definition!
-      return true             # found it
+      if it == n: return false
+      replaceSlot = h
     h = nextTry(h, high(t.data))
-  if mustRehash(len(t.data), t.counter):
+  if replaceSlot >= 0:
+    t.data[replaceSlot] = n # overwrite it with newer definition!
+    return true             # found it
+  elif mustRehash(len(t.data), t.counter):
     strTableEnlarge(t)
     strTableRawInsert(t.data, n)
   else:
diff --git a/compiler/sem.nim b/compiler/sem.nim
index 81846e1b4..5b31129a5 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -142,8 +142,8 @@ proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
 proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
   # like newSymS, but considers gensym'ed symbols
   if n.kind == nkSym:
+    # and sfGenSym in n.sym.flags:
     result = n.sym
-    internalAssert sfGenSym in result.flags
     internalAssert result.kind == kind
     # when there is a nested proc inside a template, semtmpl
     # will assign a wrong owner during the first pass over the
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 9c15be635..064bbf823 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -306,6 +306,8 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
     newbody.deepCopy = cl.c.instDeepCopy(cl.c, dc, result, cl.info)
 
 proc eraseVoidParams*(t: PType) =
+  # transform '(): void' into '()' because old parts of the compiler really
+  # doesn't deal with '(): void':
   if t.sons[0] != nil and t.sons[0].kind == tyEmpty:
     t.sons[0] = nil