summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-07-12 15:37:54 +0200
committerGitHub <noreply@github.com>2019-07-12 15:37:54 +0200
commit2895ad70c8e65cd6c220cf06c5e04ce7adfd29bd (patch)
tree96e5b5809a0dc9d7017c97bed16ec11fcda58512 /compiler
parent38b836b49e772aed38077d6aac810da183d03255 (diff)
downloadNim-2895ad70c8e65cd6c220cf06c5e04ce7adfd29bd.tar.gz
fixes tcompiletimerange [bugfix] (#11720)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/semtypes.nim7
-rw-r--r--compiler/semtypinst.nim20
2 files changed, 25 insertions, 2 deletions
diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim
index 9ff0b5c0c..e927be417 100644
--- a/compiler/semtypes.nim
+++ b/compiler/semtypes.nim
@@ -1379,8 +1379,11 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
   if tx.isNil or isTupleRecursive(tx):
     localError(c.config, n.info, "illegal recursion in type '$1'" % typeToString(result[0]))
     return errorType(c)
-  if tx != result and tx.kind == tyObject and tx.sons[0] != nil:
-    semObjectTypeForInheritedGenericInst(c, n, tx)
+  if tx != result and tx.kind == tyObject:
+    if tx.sons[0] != nil:
+      semObjectTypeForInheritedGenericInst(c, n, tx)
+    var position = 0
+    recomputeFieldPositions(tx, tx.n, position)
 
 proc maybeAliasType(c: PContext; typeExpr, prev: PType): PType =
   if typeExpr.kind in {tyObject, tyEnum, tyDistinct, tyForward} and prev != nil:
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index 9c1730798..950ec8e6b 100644
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -667,6 +667,22 @@ proc replaceTypesForLambda*(p: PContext, pt: TIdTable, n: PNode;
   result = replaceTypeVarsN(cl, n)
   popInfoContext(p.config)
 
+proc recomputeFieldPositions*(t: PType; obj: PNode; currPosition: var int) =
+  if t != nil and t.len > 0 and t.sons[0] != nil:
+    let b = skipTypes(t.sons[0], skipPtrs)
+    recomputeFieldPositions(b, b.n, currPosition)
+  case obj.kind
+  of nkRecList:
+    for i in 0 ..< sonsLen(obj): recomputeFieldPositions(nil, obj.sons[i], currPosition)
+  of nkRecCase:
+    recomputeFieldPositions(nil, obj.sons[0], currPosition)
+    for i in 1 ..< sonsLen(obj):
+      recomputeFieldPositions(nil, lastSon(obj.sons[i]), currPosition)
+  of nkSym:
+    obj.sym.position = currPosition
+    inc currPosition
+  else: discard "cannot happen"
+
 proc generateTypeInstance*(p: PContext, pt: TIdTable, info: TLineInfo,
                            t: PType): PType =
   var typeMap = initLayeredTypeMap(pt)
@@ -674,6 +690,10 @@ proc generateTypeInstance*(p: PContext, pt: TIdTable, info: TLineInfo,
   pushInfoContext(p.config, info)
   result = replaceTypeVarsT(cl, t)
   popInfoContext(p.config)
+  let objType = result.skipTypes(abstractInst)
+  if objType.kind == tyObject:
+    var position = 0
+    recomputeFieldPositions(objType, objType.n, position)
 
 proc prepareMetatypeForSigmatch*(p: PContext, pt: TIdTable, info: TLineInfo,
                                  t: PType): PType =