summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/sem.nim11
-rw-r--r--compiler/semtypes.nim23
-rw-r--r--compiler/semtypinst.nim21
-rw-r--r--compiler/sigmatch.nim3
-rw-r--r--compiler/types.nim4
5 files changed, 37 insertions, 25 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim
index df37a6384..e9c2de657 100644
--- a/compiler/sem.nim
+++ b/compiler/sem.nim
@@ -204,12 +204,15 @@ proc tryConstExpr(c: PContext, n: PNode): PNode =
   result = getConstExpr(c.module, e)
   if result != nil: return
 
-  result = evalConstExpr(c.module, e)
-  if result == nil or result.kind == nkEmpty:
+  try:
+    result = evalConstExpr(c.module, e)
+    if result == nil or result.kind == nkEmpty:
+      return nil
+
+    result = fixupTypeAfterEval(c, result, e)
+  except:
     return nil
 
-  result = fixupTypeAfterEval(c, result, e)
-  
 proc semConstExpr(c: PContext, n: PNode): PNode =
   var e = semExprWithType(c, n)
   if e == nil:
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 175901057..fb0546961 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -594,7 +594,7 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
 let typedescId = getIdent"typedesc"
 
 template shouldHaveMeta(t) =
-  InternalAssert tfHasMeta in result.lastSon.flags
+  InternalAssert tfHasMeta in t.flags
   # result.lastSon.flags.incl tfHasMeta
 
 proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
@@ -677,7 +677,8 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
     result = newTypeS(tyGenericInvokation, c)
     result.rawAddSon(paramType)
     for i in 0 .. paramType.sonsLen - 2:
-      result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true))
+      result.rawAddSon newTypeS(tyAnything, c)
+      # result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true))
     result = instGenericContainer(c, paramType.sym.info, result,
                                   allowMetaTypes = true)
     result.lastSon.shouldHaveMeta
@@ -696,20 +697,29 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
     if liftBody != nil:
       result = liftBody
       result.shouldHaveMeta
-    
+ 
+  of tyGenericInvokation:
+    for i in 1 .. <paramType.sonsLen:
+      let lifted = liftingWalk(paramType.sons[i])
+      if lifted != nil: paramType.sons[i] = lifted
+
+    let expanded = instGenericContainer(c, info, paramType,
+                                        allowMetaTypes = true)
+    result = liftingWalk(expanded)
+
   of tyTypeClass, tyBuiltInTypeClass, tyAnd, tyOr, tyNot:
     result = addImplicitGeneric(copyType(paramType, getCurrOwner(), true))
   
   of tyExpr:
     if procKind notin {skMacro, skTemplate}:
-      result = addImplicitGeneric(newTypeS(tyGenericParam, c))
+      result = addImplicitGeneric(newTypeS(tyAnything, c))
   
   of tyGenericParam:
     if tfGenericTypeParam in paramType.flags and false:
       if paramType.sonsLen > 0:
         result = liftingWalk(paramType.lastSon)
       else:
-        result = addImplicitGeneric(newTypeS(tyGenericParam, c))
+        result = addImplicitGeneric(newTypeS(tyAnything, c))
   
   else: nil
 
@@ -860,7 +870,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
       return newOrPrevType(tyError, prev, c)
 
     var isConcrete = true
-  
+ 
     for i in 1 .. <m.call.len:
       let typ = m.call[i].typ.skipTypes({tyTypeDesc})
       if containsGenericType(typ): isConcrete = false
@@ -878,6 +888,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
                                         allowMetaTypes = not isConcrete)
           if not isConcrete and result.kind == tyGenericInst:
             result.lastSon.shouldHaveMeta
+          
 
 proc semTypeExpr(c: PContext, n: PNode): PType =
   var n = semExprWithType(c, n, {efDetermineType})
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 029bf6c8c..fb7be3a38 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -263,25 +263,24 @@ proc propagateFieldFlags(t: PType, n: PNode) =
   of nkSym:
     propagateToOwner(t, n.sym.typ)
   of nkRecList, nkRecCase, nkOfBranch, nkElse:
-    for son in n.sons:
-      propagateFieldFlags(t, son)
+    if n.sons != nil:
+      for son in n.sons:
+        propagateFieldFlags(t, son)
   else: discard
 
 proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
   result = t
   if t == nil: return
 
-  if t.kind == tyStatic and t.sym != nil and t.sym.kind == skGenericParam:
-    let s = lookupTypeVar(cl, t)
-    return if s != nil: s else: t
+  #if t.kind == tyStatic and t.sym != nil and t.sym.kind == skGenericParam:
+  #  let s = lookupTypeVar(cl, t)
+  #  return if s != nil: s else: t
+
+  if t.kind in {tyStatic, tyGenericParam} + tyTypeClasses:
+    let lookup = PType(idTableGet(cl.typeMap, t))
+    if lookup != nil: return lookup
 
   case t.kind
-  of tyGenericParam, tyTypeClasses:
-    let lookup = lookupTypeVar(cl, t)
-    if lookup != nil:
-      result = lookup
-      if result.kind == tyGenericInvokation:
-        result = handleGenericInvokation(cl, result)
   of tyGenericInvokation:
     result = handleGenericInvokation(cl, t)
   of tyGenericBody:
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 13546eae2..9a00a308b 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -649,8 +649,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
     if a.kind == tyEmpty: result = isEqual
 
   of tyGenericInst:
-    if a.kind == tyGenericInst:
-      if a.base != f.base: return isNone
+    if a.kind == tyGenericInst and a.base == f.base:
       for i in 1 .. f.sonsLen-2:
         result = typeRel(c, f.sons[i], a.sons[i])
         if result == isNone: return
diff --git a/compiler/types.nim b/compiler/types.nim
index a24adb17e..1bf18fbe2 100644
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -1227,8 +1227,8 @@ proc getSize(typ: PType): BiggestInt =
   if result < 0: internalError("getSize: " & $typ.kind)
 
 proc containsGenericTypeIter(t: PType, closure: PObject): bool =
-  result = t.kind in GenericTypes + tyTypeClasses +
-                     {tyTypeDesc, tyStatic}
+  result = t.kind in GenericTypes + tyTypeClasses + {tyTypeDesc} or
+           t.kind == tyStatic and t.n == nil
 
 proc containsGenericType*(t: PType): bool = 
   result = iterOverType(t, containsGenericTypeIter, nil)