fixes #5521 object variants superclass trigger bad codegen (#6120)

This commit is contained in:
andri lim
2017-11-19 19:12:26 +07:00
committed by Andreas Rumpf
parent 035f0fb023
commit b174e9f42a
2 changed files with 29 additions and 9 deletions

View File

@@ -798,8 +798,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) =
proc genInExprAux(p: BProc, e: PNode, a, b, d: var TLoc)
proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym;
origTy: PType) =
proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym) =
var test, u, v: TLoc
for i in countup(1, sonsLen(e) - 1):
var it = e.sons[i]
@@ -811,12 +810,10 @@ proc genFieldCheck(p: BProc, e: PNode, obj: Rope, field: PSym;
assert(disc.kind == nkSym)
initLoc(test, locNone, it, OnStack)
initLocExpr(p, it.sons[1], u)
var o = obj
let d = lookupFieldAgain(p, origTy, disc.sym, o)
initLoc(v, locExpr, disc, OnUnknown)
v.r = o
v.r = obj
v.r.add(".")
v.r.add(d.loc.r)
v.r.add(disc.sym.loc.r)
genInExprAux(p, it, u, v, test)
let id = nodeTableTestOrSet(p.module.dataCache,
newStrNode(nkStrLit, field.name.s), p.module.labels)
@@ -842,7 +839,7 @@ proc genCheckedRecordField(p: BProc, e: PNode, d: var TLoc) =
if field.loc.r == nil: fillObjectFields(p.module, ty)
if field.loc.r == nil:
internalError(e.info, "genCheckedRecordField") # generate the checks:
genFieldCheck(p, e, r, field, ty)
genFieldCheck(p, e, r, field)
add(r, rfmt(nil, ".$1", field.loc.r))
putIntoDest(p, d, e.sons[0], r, a.storage)
else:
@@ -1226,7 +1223,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
if field.loc.r == nil: fillObjectFields(p.module, ty)
if field.loc.r == nil: internalError(e.info, "genObjConstr")
if it.len == 3 and optFieldCheck in p.options:
genFieldCheck(p, it.sons[2], r, field, ty)
genFieldCheck(p, it.sons[2], r, field)
add(tmp2.r, ".")
add(tmp2.r, field.loc.r)
tmp2.k = locTemp

View File

@@ -1,5 +1,7 @@
discard """
output: "23"
output: '''23
1.5
'''
"""
# bug #554, #179
@@ -25,3 +27,24 @@ type
var
it: TKeysIterator[int, string] = nil
#bug #5521
type
Texture = enum
Smooth
Coarse
FruitBase = object of RootObj
color: int
case kind: Texture
of Smooth:
skin: float64
of Coarse:
grain: int
Apple = object of FruitBase
width: int
taste: float64
var x = Apple(kind: Smooth, skin: 1.5)
var u = x.skin
echo u