Object downconversion in VM should not copy (#10378)
Hopefully the type-check phase already rejected all the invalid conversions by the time we execute the VM bytecode. Problem reported by chrisheller on the Nim Forum
This commit is contained in:
parent
3ea099bc7f
commit
44c04b3571
2 changed files with 22 additions and 0 deletions
|
|
@ -399,6 +399,11 @@ proc opConv(c: PCtx; dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType):
|
||||||
dest.floatVal = toBiggestFloat(src.intVal)
|
dest.floatVal = toBiggestFloat(src.intVal)
|
||||||
else:
|
else:
|
||||||
dest.floatVal = src.floatVal
|
dest.floatVal = src.floatVal
|
||||||
|
of tyObject:
|
||||||
|
if srctyp.skipTypes(abstractRange).kind != tyObject:
|
||||||
|
internalError(c.config, "invalid object-to-object conversion")
|
||||||
|
# A object-to-object conversion is essentially a no-op
|
||||||
|
moveConst(dest, src)
|
||||||
else:
|
else:
|
||||||
asgnComplex(dest, src)
|
asgnComplex(dest, src)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,3 +48,20 @@ let people = {
|
||||||
}.toTable()
|
}.toTable()
|
||||||
|
|
||||||
echo people["001"]
|
echo people["001"]
|
||||||
|
|
||||||
|
# Object downconversion should not copy
|
||||||
|
|
||||||
|
type
|
||||||
|
SomeBaseObj {.inheritable.} = object of RootObj
|
||||||
|
txt : string
|
||||||
|
InheritedFromBase = object of SomeBaseObj
|
||||||
|
other : string
|
||||||
|
|
||||||
|
proc initBase(sbo: var SomeBaseObj) =
|
||||||
|
sbo.txt = "Initialized string from base"
|
||||||
|
|
||||||
|
static:
|
||||||
|
var ifb2: InheritedFromBase
|
||||||
|
initBase(SomeBaseObj(ifb2))
|
||||||
|
echo repr(ifb2)
|
||||||
|
doAssert(ifb2.txt == "Initialized string from base")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue