summary refs log tree commit diff stats
path: root/compiler/semmacrosanity.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/semmacrosanity.nim')
-rw-r--r--compiler/semmacrosanity.nim16
1 files changed, 10 insertions, 6 deletions
diff --git a/compiler/semmacrosanity.nim b/compiler/semmacrosanity.nim
index 150680af7..6cd5c4a3c 100644
--- a/compiler/semmacrosanity.nim
+++ b/compiler/semmacrosanity.nim
@@ -12,25 +12,26 @@
 
 import ast, astalgo, msgs, types
 
-proc ithField(n: PNode, field: int): PSym =
+proc ithField(n: PNode, field: var int): PSym =
   result = nil
   case n.kind
   of nkRecList:
     for i in countup(0, sonsLen(n) - 1):
-      result = ithField(n.sons[i], field-i)
+      result = ithField(n.sons[i], field)
       if result != nil: return
   of nkRecCase:
     if n.sons[0].kind != nkSym: internalError(n.info, "ithField")
-    result = ithField(n.sons[0], field-1)
+    result = ithField(n.sons[0], field)
     if result != nil: return
     for i in countup(1, sonsLen(n) - 1):
       case n.sons[i].kind
       of nkOfBranch, nkElse:
-        result = ithField(lastSon(n.sons[i]), field-1)
+        result = ithField(lastSon(n.sons[i]), field)
         if result != nil: return
       else: internalError(n.info, "ithField(record case branch)")
   of nkSym:
     if field == 0: result = n.sym
+    else: dec(field)
   else: discard
 
 proc annotateType*(n: PNode, t: PType) =
@@ -39,10 +40,13 @@ proc annotateType*(n: PNode, t: PType) =
   # to not to skip tyGenericInst
   case n.kind
   of nkObjConstr:
+    let x = t.skipTypes(abstractPtrs)
     n.typ = t
     for i in 1 .. <n.len:
-      let field = x.n.ithField(i - 1)
-      if field.isNil: globalError n.info, "invalid field at index " & $i
+      var j = i-1
+      let field = x.n.ithField(j)
+      if field.isNil:
+        globalError n.info, "invalid field at index " & $i
       else:
         internalAssert(n.sons[i].kind == nkExprColonExpr)
         annotateType(n.sons[i].sons[1], field.typ)