From 44c04b35717336595dad03ac532ee9e141a0e374 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Tue, 22 Jan 2019 07:36:40 +0100 Subject: 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 --- tests/vm/tconstobj.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/vm') diff --git a/tests/vm/tconstobj.nim b/tests/vm/tconstobj.nim index 021fcb728..3cf256eed 100644 --- a/tests/vm/tconstobj.nim +++ b/tests/vm/tconstobj.nim @@ -48,3 +48,20 @@ let people = { }.toTable() 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") -- cgit 1.4.1-2-gfad0