summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2019-07-12 12:15:30 +0200
committerAraq <rumpf_a@web.de>2019-07-12 12:15:30 +0200
commit7606efc0bf57028fecc9f3295b62516eafa38e48 (patch)
tree9eb60e7caf2dd5a5e5f6f6ff528c1f3d11e9589c /compiler
parent6d125da93f54a681561ffd428ac0b6aeb132aefd (diff)
downloadNim-7606efc0bf57028fecc9f3295b62516eafa38e48.tar.gz
[bugfix] VM: finally do inheritance properly
Diffstat (limited to 'compiler')
-rw-r--r--compiler/vmgen.nim23
1 files changed, 12 insertions, 11 deletions
diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim
index e63eb1fd9..37706f1ea 100644
--- a/compiler/vmgen.nim
+++ b/compiler/vmgen.nim
@@ -1719,19 +1719,24 @@ proc genArrAccess(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) =
   else:
     genArrAccess2(c, n, dest, opcLdArr, flags)
 
-proc getNullValueAux(obj: PNode, result: PNode; conf: ConfigRef) =
+proc getNullValueAux(t: PType; obj: PNode, result: PNode; conf: ConfigRef; currPosition: var int) =
+  if t != nil and t.len > 0 and t.sons[0] != nil:
+    let b = skipTypes(t.sons[0], skipPtrs)
+    getNullValueAux(b, b.n, result, conf, currPosition)
   case obj.kind
   of nkRecList:
-    for i in 0 ..< sonsLen(obj): getNullValueAux(obj.sons[i], result, conf)
+    for i in 0 ..< sonsLen(obj): getNullValueAux(nil, obj.sons[i], result, conf, currPosition)
   of nkRecCase:
-    getNullValueAux(obj.sons[0], result, conf)
+    getNullValueAux(nil, obj.sons[0], result, conf, currPosition)
     for i in 1 ..< sonsLen(obj):
-      getNullValueAux(lastSon(obj.sons[i]), result, conf)
+      getNullValueAux(nil, lastSon(obj.sons[i]), result, conf, currPosition)
   of nkSym:
     let field = newNodeI(nkExprColonExpr, result.info)
     field.add(obj)
     field.add(getNullValue(obj.sym.typ, result.info, conf))
     addSon(result, field)
+    doAssert obj.sym.position == currPosition
+    inc currPosition
   else: globalError(conf, result.info, "cannot create null element for: " & $obj)
 
 proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode =
@@ -1759,13 +1764,9 @@ proc getNullValue(typ: PType, info: TLineInfo; conf: ConfigRef): PNode =
   of tyObject:
     result = newNodeIT(nkObjConstr, info, t)
     result.add(newNodeIT(nkEmpty, info, t))
-    # initialize inherited fields:
-    var base = t.sons[0]
-    while base != nil:
-      let b = skipTypes(base, skipPtrs)
-      getNullValueAux(b.n, result, conf)
-      base = b.sons[0]
-    getNullValueAux(t.n, result, conf)
+    # initialize inherited fields, and all in the correct order:
+    var currPosition = 0
+    getNullValueAux(t, t.n, result, conf, currPosition)
   of tyArray:
     result = newNodeIT(nkBracket, info, t)
     for i in 0 ..< int(lengthOrd(conf, t)):