summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2014-03-10 13:04:22 +0200
committerZahary Karadjov <zahary@gmail.com>2014-03-10 13:04:22 +0200
commit85fe5e1940efbde41ac88113e8cc6a954b0414b9 (patch)
tree644b257645e93a45cb02f2a7d8d336b408683b5b
parentd5798b43dec547f372eb49d5a8848a9970b12260 (diff)
downloadNim-85fe5e1940efbde41ac88113e8cc6a954b0414b9.tar.gz
fix #988
trivial crash caused due to unchecked iteration over an empty reclist
-rw-r--r--compiler/semexprs.nim7
-rw-r--r--compiler/semtypinst.nim5
2 files changed, 6 insertions, 6 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index f2c5e2854..62a816a50 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -931,7 +931,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
   var ty = n.sons[0].typ
   var f: PSym = nil
   result = nil
-  if isTypeExpr(n.sons[0]) or ty.kind == tyTypeDesc and ty.base.kind != tyNone:
+  if isTypeExpr(n.sons[0]) or (ty.kind == tyTypeDesc and ty.base.kind != tyNone):
     if ty.kind == tyTypeDesc: ty = ty.base
     case ty.kind
     of tyEnum:
@@ -940,7 +940,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
         f = getSymFromList(ty.n, i)
         if f != nil: break 
         ty = ty.sons[0]         # enum inheritance
-      if f != nil: 
+      if f != nil:
         result = newSymNode(f)
         result.info = n.info
         result.typ = ty
@@ -950,7 +950,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
       return readTypeParameter(c, ty, i, n.info)
     of tyObject, tyTuple:
       if ty.n.kind == nkRecList:
-        for field in ty.n.sons:
+        for field in ty.n:
           if field.sym.name == i:
             n.typ = newTypeWithSons(c, tyFieldAccessor, @[ty, field.sym.typ])
             n.typ.n = copyTree(n)
@@ -962,6 +962,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
     # XXX: This is probably not relevant any more
     # reset to prevent 'nil' bug: see "tests/reject/tenumitems.nim":
     ty = n.sons[0].typ
+    return nil
     
   ty = skipTypes(ty, {tyGenericInst, tyVar, tyPtr, tyRef})
   var check: PNode = nil
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 4229f4797..80e2aa284 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -320,9 +320,8 @@ proc propagateFieldFlags(t: PType, n: PNode) =
   of nkSym:
     propagateToOwner(t, n.sym.typ)
   of nkRecList, nkRecCase, nkOfBranch, nkElse:
-    if n.sons != nil:
-      for son in n.sons:
-        propagateFieldFlags(t, son)
+    for son in n:
+      propagateFieldFlags(t, son)
   else: discard
 
 proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =