summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2014-03-16 18:34:37 +0200
committerZahary Karadjov <zahary@gmail.com>2014-03-16 20:42:49 +0200
commit49b0440c47b1f22bf2b84083b0c2b79fb60fdfd5 (patch)
treecc3e9612054ebcad226d0f7bffc3237d62d30005 /compiler
parentf0953db3ba59f2e23df2fb7932c672f5020db5fb (diff)
downloadNim-49b0440c47b1f22bf2b84083b0c2b79fb60fdfd5.tar.gz
make some tests green
Diffstat (limited to 'compiler')
-rw-r--r--compiler/lookups.nim5
-rw-r--r--compiler/semexprs.nim10
-rw-r--r--compiler/seminst.nim16
-rw-r--r--compiler/semtypes.nim7
-rw-r--r--compiler/sigmatch.nim9
-rw-r--r--compiler/vmgen.nim2
6 files changed, 32 insertions, 17 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim
index 8239f2a47..60125177c 100644
--- a/compiler/lookups.nim
+++ b/compiler/lookups.nim
@@ -127,7 +127,10 @@ proc ensureNoMissingOrUnusedSymbols(scope: PScope) =
     elif {sfUsed, sfExported} * s.flags == {} and optHints in s.options: 
       # BUGFIX: check options in s!
       if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam}:
-        message(s.info, hintXDeclaredButNotUsed, getSymRepr(s))
+        # XXX: implicit type params are currently skTypes
+        # maybe they can be made skGenericParam as well.
+        if s.typ != nil and tfImplicitTypeParam notin s.typ.flags:
+          message(s.info, hintXDeclaredButNotUsed, getSymRepr(s))
     s = nextIter(it, scope.symbols)
   
 proc wrongRedefinition*(info: TLineInfo, s: string) =
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 2c7408047..7e141cb24 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -325,8 +325,13 @@ proc isOpImpl(c: PContext, n: PNode): PNode =
                                         tfIterator notin t.flags))
   else:
     var t2 = n[2].typ.skipTypes({tyTypeDesc})
+    # XXX: liftParamType started to perform addDecl
+    # we could do that instead in semTypeNode by snooping for added
+    # gnrc. params, then it won't be necessary to open a new scope here
+    openScope(c)
     let lifted = liftParamType(c, skType, newNodeI(nkArgList, n.info),
                                t2, ":anon", n.info)
+    closeScope(c)
     if lifted != nil: t2 = lifted
     var m: TCandidate
     initCandidate(c, m, t2)
@@ -1257,8 +1262,9 @@ proc semProcBody(c: PContext, n: PNode): PNode =
       result = semAsgn(c, a)
   else:
     discardCheck(c, result)
-
-  if c.p.resultSym != nil and c.p.resultSym.typ.isMetaType:
+  
+  if c.p.owner.kind notin {skMacro, skTemplate} and
+     c.p.resultSym != nil and c.p.resultSym.typ.isMetaType:
     localError(c.p.resultSym.info, errCannotInferReturnType)
 
   closeScope(c)
diff --git a/compiler/seminst.nim b/compiler/seminst.nim
index 3d3227e4e..a5149a842 100644
--- a/compiler/seminst.nim
+++ b/compiler/seminst.nim
@@ -117,12 +117,9 @@ proc fixupInstantiatedSymbols(c: PContext, s: PSym) =
       var oldPrc = c.generics[i].inst.sym
       pushInfoContext(oldPrc.info)
       openScope(c)
-      pushProcCon(c, oldPrc)
-      addProcDecls(c, oldPrc)
       var n = oldPrc.ast
       n.sons[bodyPos] = copyTree(s.getBody)
       instantiateBody(c, n, oldPrc)
-      popProcCon(c)
       closeScope(c)
       popInfoContext()
 
@@ -164,10 +161,11 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
   # at this point semtypinst have to become part of sem, because it
   # will need to use openScope, addDecl, etc
   #
+  addDecl(c, prc)
+  
   pushInfoContext(info)
   var cl = initTypeVars(c, pt, info)
   var result = instCopyType(cl, prc.typ)
-  addDecl(c, prc)
   let originalParams = result.n
   result.n = originalParams.shallowCopy
   
@@ -175,10 +173,14 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
     result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
     propagateToOwner(result, result.sons[i])
     let param = replaceTypeVarsN(cl, originalParams[i])
-    internalAssert param.kind == nkSym
     result.n.sons[i] = param
-    addDecl(c, param.sym)
-  
+    if param.kind == nkSym:
+      # XXX: this won't be true for void params
+      # implement pass-through of void params and
+      # the "sort by distance to point" container
+      param.sym.owner = prc
+      addDecl(c, param.sym)
+    
   result.sons[0] = replaceTypeVarsT(cl, result.sons[0])
   result.n.sons[0] = originalParams[0].copyTree
   
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 4e97a6744..06fcd74b4 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -220,7 +220,7 @@ proc semArray(c: PContext, n: PNode, prev: PType): PType =
     else:
       let e = semExprWithType(c, n.sons[1], {efDetermineType})
       if e.typ.kind == tyFromExpr:
-        indx = e.typ
+        indx = makeRangeWithStaticExpr(c, e.typ.n)
       elif e.kind in {nkIntLit..nkUInt64Lit}:
         indx = makeRangeType(c, 0, e.intVal-1, n.info, e.typ)
       elif e.kind == nkSym and e.typ.kind == tyStatic:
@@ -783,7 +783,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
         result = paramType
         result.lastSon.shouldHaveMeta
 
-    let liftBody = liftingWalk(paramType.lastSon)
+    let liftBody = liftingWalk(paramType.lastSon, true)
     if liftBody != nil:
       result = liftBody
       result.shouldHaveMeta
@@ -795,7 +795,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
 
     let expanded = instGenericContainer(c, info, paramType,
                                         allowMetaTypes = true)
-    result = liftingWalk(expanded)
+    result = liftingWalk(expanded, true)
 
   of tyUserTypeClass, tyBuiltInTypeClass, tyAnd, tyOr, tyNot:
     result = addImplicitGeneric(copyType(paramType, getCurrOwner(), true))
@@ -964,6 +964,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
   elif s.typ.kind != tyGenericBody:
     #we likely got code of the form TypeA[TypeB] where TypeA is
     #not generic.
+    debug s.typ
     localError(n.info, errNoGenericParamsAllowedForX, s.name.s)
     return newOrPrevType(tyError, prev, c)
   else:
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index b87d27cb4..662268380 100644
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -522,8 +522,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
 
   template bindingRet(res) =
     when res == isGeneric:
-      let bound = aOrig.skipTypes({tyRange}).skipIntLit
-      put(c.bindings, f, bound)
+      if doBind:
+        let bound = aOrig.skipTypes({tyRange}).skipIntLit
+        if doBind: put(c.bindings, f, bound)
     return res
 
   template considerPreviousT(body: stmt) {.immediate.} =
@@ -869,7 +870,9 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
         # any value" and what we need is "match any type", which can be encoded
         # by a tyTypeDesc params. Unfortunately, this requires more substantial
         # changes in semtypinst and elsewhere.
-        if a.kind == tyTypeDesc or tfWildcard in a.flags:
+        if tfWildcard in a.flags:
+          result = isGeneric
+        elif a.kind == tyTypeDesc:
           if f.sonsLen == 0:
             result = isGeneric
           else:
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index 0fc71189d..d3eda5db3 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -1569,7 +1569,7 @@ proc genProc(c: PCtx; s: PSym): int =
     c.gABC(body, opcEof, eofInstr.regA)
     c.optimizeJumps(result)
     s.offset = c.prc.maxSlots
-    #if s.name.s == "xmlConstructor":
+    #if s.name.s == "foo":
     #  echo renderTree(body)
     #  c.echoCode(result)
     c.prc = oldPrc