summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-07-14 16:11:42 +0200
committerAraq <rumpf_a@web.de>2019-07-14 16:11:42 +0200
commit58e0dad3712d4e423fd26bd91b26b8a31a85bf33 (patch)
tree4ed07b8c4acd2d8c1a15e9303ffcbe586388b8e7 /compiler
parente06046ab51660f2f227618ad263b64911c4d8a63 (diff)
downloadNim-58e0dad3712d4e423fd26bd91b26b8a31a85bf33.tar.gz
'nim check' stability improvements
Diffstat (limited to 'compiler')
-rw-r--r--compiler/nimsets.nim6
-rw-r--r--compiler/sigmatch.nim3
-rw-r--r--compiler/types.nim6
-rw-r--r--compiler/vm.nim10
4 files changed, 17 insertions, 8 deletions
diff --git a/compiler/nimsets.nim b/compiler/nimsets.nim
index b13f3be3d..c2436dff0 100644
--- a/compiler/nimsets.nim
+++ b/compiler/nimsets.nim
@@ -65,12 +65,12 @@ proc toBitSet*(conf: ConfigRef; s: PNode, b: var TBitSet) =
   bitSetInit(b, int(getSize(conf, s.typ)))
   for i in 0 ..< sonsLen(s):
     if s.sons[i].kind == nkRange:
-      j = getOrdValue(s.sons[i].sons[0])
-      while j <= getOrdValue(s.sons[i].sons[1]):
+      j = getOrdValue(s.sons[i].sons[0], first)
+      while j <= getOrdValue(s.sons[i].sons[1], first):
         bitSetIncl(b, j - first)
         inc(j)
     else:
-      bitSetIncl(b, getOrdValue(s.sons[i]) - first)
+      bitSetIncl(b, getOrdValue(s.sons[i], first) - first)
 
 proc toTreeSet*(conf: ConfigRef; s: TBitSet, settype: PType, info: TLineInfo): PNode =
   var
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 003bca646..655ee83f0 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -2461,7 +2461,8 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
             # we end up here if the argument can be converted into the varargs
             # formal (eg. seq[T] -> varargs[T]) but we have already instantiated
             # a container
-            assert arg.kind == nkHiddenStdConv
+            #assert arg.kind == nkHiddenStdConv # for 'nim check'
+            # this assertion can be off
             localError(c.config, n.sons[a].info, "cannot convert $1 to $2" % [
               typeToString(n.sons[a].typ), typeToString(formal.typ) ])
             m.state = csNoMatch
diff --git a/compiler/types.nim b/compiler/types.nim
index 0b5fa7ef7..e41f45780 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -77,12 +77,12 @@ proc isPureObject*(typ: PType): bool =
     t = t.sons[0].skipTypes(skipPtrs)
   result = t.sym != nil and sfPure in t.sym.flags
 
-proc getOrdValue*(n: PNode): BiggestInt =
+proc getOrdValue*(n: PNode; onError = high(BiggestInt)): BiggestInt =
   case n.kind
   of nkCharLit..nkUInt64Lit: n.intVal
   of nkNilLit: 0
-  of nkHiddenStdConv: getOrdValue(n.sons[1])
-  else: high(BiggestInt)
+  of nkHiddenStdConv: getOrdValue(n.sons[1], onError)
+  else: onError
 
 proc getFloatValue*(n: PNode): BiggestFloat =
   case n.kind
diff --git a/compiler/vm.nim b/compiler/vm.nim
index f2b288216..bb8c6bbf2 100644
--- a/compiler/vm.nim
+++ b/compiler/vm.nim
@@ -2061,13 +2061,21 @@ iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) =
   for i in 0 ..< gp.len:
     let genericParam = gp[i].sym
     let posInCall = macroSym.typ.len + i
-    yield (genericParam, call[posInCall])
+    if posInCall < call.len:
+      yield (genericParam, call[posInCall])
 
 # to prevent endless recursion in macro instantiation
 const evalMacroLimit = 1000
 
+proc errorNode(owner: PSym, n: PNode): PNode =
+  result = newNodeI(nkEmpty, n.info)
+  result.typ = newType(tyError, owner)
+  result.typ.flags.incl tfCheckedForDestructor
+
 proc evalMacroCall*(module: PSym; g: ModuleGraph;
                     n, nOrig: PNode, sym: PSym): PNode =
+  if g.config.errorCounter > 0: return errorNode(module, n)
+
   # XXX globalError() is ugly here, but I don't know a better solution for now
   inc(g.config.evalMacroCounter)
   if g.config.evalMacroCounter > evalMacroLimit: