summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rwxr-xr-xcompiler/ccgexprs.nim41
-rwxr-xr-xcompiler/semstmts.nim5
-rwxr-xr-xcompiler/semtypinst.nim15
3 files changed, 32 insertions, 29 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim
index 7c9b346e6..ef0d6bc85 100755
--- a/compiler/ccgexprs.nim
+++ b/compiler/ccgexprs.nim
@@ -1058,8 +1058,7 @@ proc genNew(p: BProc, e: PNode) =
 proc genNewSeq(p: BProc, e: PNode) =
   var
     a, b, c: TLoc
-    seqtype: PType
-  seqType = skipTypes(e.sons[1].typ, abstractVarRange)
+  var seqType = skipTypes(e.sons[1].typ, abstractVarRange)
   InitLocExpr(p, e.sons[1], a)
   InitLocExpr(p, e.sons[2], b)
   initLoc(c, locExpr, a.t, OnHeap)
@@ -1069,15 +1068,12 @@ proc genNewSeq(p: BProc, e: PNode) =
   genAssignment(p, a, c, {})
 
 proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) =
-  var
-    a: TLoc
-    dest, t: PType
-    r, nilcheck: PRope
+  var a: TLoc
   initLocExpr(p, x, a)
-  dest = skipTypes(typ, abstractPtrs)
-  r = rdLoc(a)
-  nilCheck = nil
-  t = skipTypes(a.t, abstractInst)
+  var dest = skipTypes(typ, abstractPtrs)
+  var r = rdLoc(a)
+  var nilCheck: PRope = nil
+  var t = skipTypes(a.t, abstractInst)
   while t.kind in {tyVar, tyPtr, tyRef}:
     if t.kind != tyVar: nilCheck = r
     r = ropef("(*$1)", [r])
@@ -1546,7 +1542,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
   of mStrToStr: expr(p, e.sons[1], d)
   of mEnumToStr: genRepr(p, e, d)
   of mAssert:
-    if (optAssert in p.Options):
+    if optAssert in p.Options:
       expr(p, e.sons[1], d)
       line = toRope(toLinenumber(e.info))
       filen = makeCString(ToFilename(e.info))
@@ -1689,22 +1685,19 @@ proc genStmtListExpr(p: BProc, n: PNode, d: var TLoc) =
   if length > 0: expr(p, n.sons[length - 1], d)
 
 proc upConv(p: BProc, n: PNode, d: var TLoc) =
-  var
-    a: TLoc
-    dest, t: PType
-    r, nilCheck: PRope
+  var a: TLoc
   initLocExpr(p, n.sons[0], a)
-  dest = skipTypes(n.typ, abstractPtrs)
-  if (optObjCheck in p.options) and not (isPureObject(dest)):
-    r = rdLoc(a)
-    nilCheck = nil
-    t = skipTypes(a.t, abstractInst)
+  var dest = skipTypes(n.typ, abstractPtrs)
+  if optObjCheck in p.options and not isPureObject(dest):
+    var r = rdLoc(a)
+    var nilCheck: PRope = nil
+    var t = skipTypes(a.t, abstractInst)
     while t.kind in {tyVar, tyPtr, tyRef}:
       if t.kind != tyVar: nilCheck = r
       r = ropef("(*$1)", [r])
       t = skipTypes(t.sons[0], abstractInst)
     if gCmd != cmdCompileToCpp:
-      while (t.kind == tyObject) and (t.sons[0] != nil):
+      while t.kind == tyObject and t.sons[0] != nil:
         app(r, ".Sup")
         t = skipTypes(t.sons[0], abstractInst)
     if nilCheck != nil:
@@ -1753,7 +1746,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
       putLocIntoDest(p, d, sym.loc)
     of skProc, skConverter:
       genProc(p.module, sym)
-      if ((sym.loc.r == nil) or (sym.loc.t == nil)):
+      if sym.loc.r == nil or sym.loc.t == nil:
         InternalError(e.info, "expr: proc not init " & sym.name.s)
       putLocIntoDest(p, d, sym.loc)
     of skConst:
@@ -1768,7 +1761,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
       putIntoDest(p, d, e.typ, toRope(sym.position))
     of skVar, skResult:
       if sfGlobal in sym.flags: genVarPrototype(p.module, sym)
-      if ((sym.loc.r == nil) or (sym.loc.t == nil)):
+      if sym.loc.r == nil or sym.loc.t == nil:
         InternalError(e.info, "expr: var not init " & sym.name.s)
       if sfThreadVar in sym.flags:
         AccessThreadLocalVar(p, sym)
@@ -1803,7 +1796,7 @@ proc expr(p: BProc, e: PNode, d: var TLoc) =
       genCall(p, e, d)
   of nkCurly: genSetConstr(p, e, d)
   of nkBracket:
-    if (skipTypes(e.typ, abstractVarRange).kind == tySequence):
+    if skipTypes(e.typ, abstractVarRange).kind == tySequence:
       genSeqConstr(p, e, d)
     else:
       genArrayConstr(p, e, d)
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 86d5b0f26..c37706f3a 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -489,13 +489,16 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
         InternalError(a.info, "semTypeSection: containerID")
       s.typ.containerID = getID()
       a.sons[1] = semGenericParamList(c, a.sons[1], s.typ)
+      s.typ.size = -1 # could not be computed properly
       # we fill it out later. For magic generics like 'seq', it won't be filled
       # so we use tyEmpty instead of nil to not crash for strange conversions
       # like: mydata.seq
       addSon(s.typ, newTypeS(tyEmpty, c))
       s.ast = a
       var body = semTypeNode(c, a.sons[2], nil)
-      if body != nil: body.sym = s
+      if body != nil: 
+        body.sym = s
+        body.size = -1 # could not be computed properly
       s.typ.sons[sonsLen(s.typ) - 1] = body
       popOwner()
       closeScope(c.tab)
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 420c84193..41ec8ddac 100755
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -11,6 +11,12 @@
 
 import ast, astalgo, msgs, types, semdata
 
+proc checkPartialConstructedType(info: TLineInfo, t: PType) =
+  if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject:
+    LocalError(info, errInvalidPragmaX, "acyclic")
+  elif t.kind == tyVar and t.sons[0].kind == tyVar:
+    LocalError(info, errVarVarTypeNotAllowed)
+
 proc checkConstructedType*(info: TLineInfo, t: PType) = 
   if tfAcyclic in t.flags and skipTypes(t, abstractInst).kind != tyObject: 
     LocalError(info, errInvalidPragmaX, "acyclic")
@@ -22,7 +28,7 @@ proc checkConstructedType*(info: TLineInfo, t: PType) =
     if t.kind == tyObject and t.sons[0] != nil:
       if t.sons[0].kind != tyObject or tfFinal in t.sons[0].flags: 
         localError(info, errInheritanceOnlyWithNonFinalObjects)
-    
+  
 proc containsGenericTypeIter(t: PType, closure: PObject): bool = 
   result = t.kind in GenericTypes
 
@@ -121,10 +127,10 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
   var newbody = ReplaceTypeVarsT(cl, lastSon(body))
   newbody.flags = newbody.flags + t.flags + body.flags
   newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
-  addSon(result, newbody)   
+  addSon(result, newbody)
   #writeln(output, ropeToStr(Typetoyaml(newbody)));
-  checkConstructedType(cl.info, newbody)
-    
+  checkPartialConstructedType(cl.info, newbody)
+  
 proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType = 
   result = t
   if t == nil: return 
@@ -139,6 +145,7 @@ proc ReplaceTypeVarsT*(cl: var TReplTypeVars, t: PType): PType =
   else:
     if containsGenericType(t):
       result = copyType(t, t.owner, false)
+      result.size = -1 # needs to be recomputed
       for i in countup(0, sonsLen(result) - 1):
         result.sons[i] = ReplaceTypeVarsT(cl, result.sons[i])
       result.n = ReplaceTypeVarsN(cl, result.n)