summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/astalgo.nim13
-rw-r--r--compiler/semexprs.nim6
-rw-r--r--compiler/semtypinst.nim8
-rw-r--r--compiler/sigmatch.nim39
4 files changed, 42 insertions, 24 deletions
diff --git a/compiler/astalgo.nim b/compiler/astalgo.nim
index fd6774e7a..6c48dd00f 100644
--- a/compiler/astalgo.nim
+++ b/compiler/astalgo.nim
@@ -430,11 +430,14 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int): PRope =
     appf(result, ",$N$1\"info\": $2", [istr, lineInfoToStr(n.info)])
     appf(result, "$N$1}", [spaces(indent)])
 
-proc debug(n: PSym) = 
-  #writeln(stdout, ropeToStr(symToYaml(n, 0, 1)))
-  writeln(stdout, ropeToStr(ropef("$1_$2: $3, $4", [
-    toRope(n.name.s), toRope(n.id), flagsToStr(n.flags), 
-    flagsToStr(n.loc.flags)])))
+proc debug(n: PSym) =
+  if n == nil:
+    writeln(stdout, "null")
+  else:
+    #writeln(stdout, ropeToStr(symToYaml(n, 0, 1)))
+    writeln(stdout, ropeToStr(ropef("$1_$2: $3, $4", [
+      toRope(n.name.s), toRope(n.id), flagsToStr(n.flags), 
+      flagsToStr(n.loc.flags)])))
 
 proc debug(n: PType) = 
   writeln(stdout, ropeToStr(debugType(n)))
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 5206d88ac..b9df29d39 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -248,7 +248,11 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode =
     of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt8, tyUInt16, tyUInt32: 
       # do not skip the range!
       n.typ = n.sons[1].typ.skipTypes(abstractVar)
-    else: LocalError(n.info, errInvalidArgForX, opToStr[m])
+    of tyGenericParam:
+      # leave it for now, it will be resolved in semtypinst
+      n.typ = getSysType(tyInt)
+    else:
+      LocalError(n.info, errInvalidArgForX, opToStr[m])
   result = n
 
 proc semSizeof(c: PContext, n: PNode): PNode =
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 0c15c7248..b638449d2 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -148,12 +148,13 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
   if result != nil: return
   for i in countup(1, sonsLen(t) - 1):
     var x = t.sons[i]
-    if x.kind == tyGenericParam: 
+    if x.kind == tyGenericParam:
       x = lookupTypeVar(cl, x)
       if header == nil: header = copyType(t, t.owner, false)
       header.sons[i] = x
       propagateToOwner(header, x)
-      #idTablePut(cl.typeMap, body.sons[i-1], x)
+      #idTablePut(cl.typeMap, body.sons[i-1], x)  
+
   if header != nil:
     # search again after first pass:
     result = searchInstTypes(header)
@@ -200,6 +201,9 @@ proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
     result = lookupTypeVar(cl, t)
     if result.kind == tyGenericInvokation:
       result = handleGenericInvokation(cl, result)
+  of tyExpr:
+    if t.sym != nil and t.sym.kind == skGenericParam:
+      result = lookupTypeVar(cl, t)
   of tyGenericInvokation: 
     result = handleGenericInvokation(cl, t)
   of tyGenericBody:
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 5411904df..ceb8ad156 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -619,7 +619,10 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
         else:
           result = isNone
       else:
-        result = matchTypeClass(c, f, a)
+        if a.kind == tyTypeClass:
+          result = isGeneric
+        else:
+          result = matchTypeClass(c, f, a)
         
       if result == isGeneric:
         var concrete = concreteType(c, a)
@@ -782,21 +785,25 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
     if fMaybeExpr.sonsLen == 0:
       r = isGeneric
     else:
-      let match = matchTypeClass(m, fMaybeExpr, a)
-      if match != isGeneric: r = isNone
+      if a.kind == tyExpr:
+        InternalAssert a.len > 0
+        r = typeRel(m, f.lastSon, a.lastSon)
       else:
-        # XXX: Ideally, this should happen much earlier somewhere near 
-        # semOpAux, but to do that, we need to be able to query the 
-        # overload set to determine whether compile-time value is expected
-        # for the param before entering the full-blown sigmatch algorithm.
-        # This is related to the immediate pragma since querying the
-        # overload set could help there too.
-        var evaluated = c.semConstExpr(c, arg)
-        if evaluated != nil:
-          r = isGeneric
-          arg.typ = newTypeS(tyExpr, c)
-          arg.typ.sons = @[evaluated.typ]
-          arg.typ.n = evaluated
+        let match = matchTypeClass(m, fMaybeExpr, a)
+        if match != isGeneric: r = isNone
+        else:
+          # XXX: Ideally, this should happen much earlier somewhere near 
+          # semOpAux, but to do that, we need to be able to query the 
+          # overload set to determine whether compile-time value is expected
+          # for the param before entering the full-blown sigmatch algorithm.
+          # This is related to the immediate pragma since querying the
+          # overload set could help there too.
+          var evaluated = c.semConstExpr(c, arg)
+          if evaluated != nil:
+            r = isGeneric
+            arg.typ = newTypeS(tyExpr, c)
+            arg.typ.sons = @[evaluated.typ]
+            arg.typ.n = evaluated
         
     if r == isGeneric:
       put(m.bindings, f, arg.typ)
@@ -812,7 +819,7 @@ proc ParamTypesMatchAux(c: PContext, m: var TCandidate, f, a: PType,
       r = typeRel(m, f, a)
   else:
     r = typeRel(m, f, a)
-  
+
   case r
   of isConvertible: 
     inc(m.convMatches)