fixes #575
This commit is contained in:
parent
138db5a85d
commit
275c7ccf82
5 changed files with 46 additions and 10 deletions
|
|
@ -304,7 +304,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
of tyObject:
|
of tyObject:
|
||||||
# XXX: check for subtyping?
|
# XXX: check for subtyping?
|
||||||
if needsComplexAssignment(ty):
|
if needsComplexAssignment(ty):
|
||||||
if asgnComplexity(ty.n) <= 4:
|
if ty.sons[0].isNil and asgnComplexity(ty.n) <= 4:
|
||||||
discard getTypeDesc(p.module, ty)
|
discard getTypeDesc(p.module, ty)
|
||||||
internalAssert ty.n != nil
|
internalAssert ty.n != nil
|
||||||
genOptAsgnObject(p, dest, src, flags, ty.n)
|
genOptAsgnObject(p, dest, src, flags, ty.n)
|
||||||
|
|
@ -1017,7 +1017,6 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
rawGenNew(p, tmp, nil)
|
rawGenNew(p, tmp, nil)
|
||||||
t = t.sons[0].skipTypes(abstractInst)
|
t = t.sons[0].skipTypes(abstractInst)
|
||||||
r = ropef("(*$1)", r)
|
r = ropef("(*$1)", r)
|
||||||
# XXX object initialization? but not necessary for temps, is it?
|
|
||||||
discard getTypeDesc(p.module, t)
|
discard getTypeDesc(p.module, t)
|
||||||
for i in 1 .. <e.len:
|
for i in 1 .. <e.len:
|
||||||
let it = e.sons[i]
|
let it = e.sons[i]
|
||||||
|
|
|
||||||
|
|
@ -384,12 +384,6 @@ proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) =
|
||||||
if not immediateAsgn:
|
if not immediateAsgn:
|
||||||
constructLoc(p, v.loc)
|
constructLoc(p, v.loc)
|
||||||
|
|
||||||
proc initTemp(p: BProc, tmp: var TLoc) =
|
|
||||||
# XXX: This is still suspicious.
|
|
||||||
# Objects should always be constructed?
|
|
||||||
if containsGarbageCollectedRef(tmp.t) or isInvalidReturnType(tmp.t):
|
|
||||||
constructLoc(p, tmp)
|
|
||||||
|
|
||||||
proc getTemp(p: BProc, t: PType, result: var TLoc) =
|
proc getTemp(p: BProc, t: PType, result: var TLoc) =
|
||||||
inc(p.labels)
|
inc(p.labels)
|
||||||
if gCmd == cmdCompileToLLVM:
|
if gCmd == cmdCompileToLLVM:
|
||||||
|
|
@ -402,7 +396,7 @@ proc getTemp(p: BProc, t: PType, result: var TLoc) =
|
||||||
result.t = getUniqueType(t)
|
result.t = getUniqueType(t)
|
||||||
result.s = OnStack
|
result.s = OnStack
|
||||||
result.flags = {}
|
result.flags = {}
|
||||||
initTemp(p, result)
|
constructLoc(p, result)
|
||||||
|
|
||||||
proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
proc keepAlive(p: BProc, toKeepAlive: TLoc) =
|
||||||
when false:
|
when false:
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,8 @@ proc genericAssignAux(dest, src: Pointer, mt: PNimType, shallow: bool) =
|
||||||
# sequence reallocations:
|
# sequence reallocations:
|
||||||
var pint = cast[ptr PNimType](dest)
|
var pint = cast[ptr PNimType](dest)
|
||||||
pint[] = cast[ptr PNimType](src)[]
|
pint[] = cast[ptr PNimType](src)[]
|
||||||
|
if mt.base != nil:
|
||||||
|
genericAssignAux(dest, src, mt.base, shallow)
|
||||||
genericAssignAux(dest, src, mt.node, shallow)
|
genericAssignAux(dest, src, mt.node, shallow)
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
genericAssignAux(dest, src, mt.node, shallow)
|
genericAssignAux(dest, src, mt.node, shallow)
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,8 @@ proc storeAux(dest, src: Pointer, mt: PNimType, t: PRawChannel,
|
||||||
var pint = cast[ptr PNimType](dest)
|
var pint = cast[ptr PNimType](dest)
|
||||||
# XXX use dynamic type here!
|
# XXX use dynamic type here!
|
||||||
pint[] = mt
|
pint[] = mt
|
||||||
|
if mt.base != nil:
|
||||||
|
storeAux(dest, src, mt.base, t, mode)
|
||||||
storeAux(dest, src, mt.node, t, mode)
|
storeAux(dest, src, mt.node, t, mode)
|
||||||
of tyTuple:
|
of tyTuple:
|
||||||
storeAux(dest, src, mt.node, t, mode)
|
storeAux(dest, src, mt.node, t, mode)
|
||||||
|
|
|
||||||
39
tests/run/tobjasgn.nim
Normal file
39
tests/run/tobjasgn.nim
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
discard """
|
||||||
|
output: '''0
|
||||||
|
pre test a:test b:1 c:2 haha:3
|
||||||
|
assignment test a:test b:1 c:2 haha:3
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
type TSomeObj = object of TObject
|
||||||
|
Variable: int
|
||||||
|
|
||||||
|
var a = TSomeObj()
|
||||||
|
|
||||||
|
echo a.Variable.`$`
|
||||||
|
|
||||||
|
# bug #575
|
||||||
|
|
||||||
|
type
|
||||||
|
Something = object of Tobject
|
||||||
|
a: string
|
||||||
|
b, c: int32
|
||||||
|
|
||||||
|
type
|
||||||
|
Other = object of Something
|
||||||
|
haha: int
|
||||||
|
|
||||||
|
proc `$`(x: Other): string =
|
||||||
|
result = "a:" & x.a & " b:" & $x.b & " c:" & $x.c & " haha:" & $x.haha
|
||||||
|
|
||||||
|
var
|
||||||
|
t: Other
|
||||||
|
|
||||||
|
t.a = "test"
|
||||||
|
t.b = 1
|
||||||
|
t.c = 2
|
||||||
|
t.haha = 3
|
||||||
|
|
||||||
|
echo "pre test ", $t
|
||||||
|
var x = t
|
||||||
|
echo "assignment test ", x
|
||||||
Loading…
Add table
Add a link
Reference in a new issue