diff options
author | cooldome <ariabushenko@bk.ru> | 2020-05-12 10:23:05 +0100 |
---|---|---|
committer | cooldome <ariabushenko@bk.ru> | 2020-05-12 10:23:05 +0100 |
commit | 2d7ccf09282ba7f7156b2f2d9893cb083cd18549 (patch) | |
tree | 32838e97316272fdb14ec37858560c32b3096837 | |
parent | 55446c05a4ed726a6aa26bdf5f0da1db5ad7d5f1 (diff) | |
download | Nim-2d7ccf09282ba7f7156b2f2d9893cb083cd18549.tar.gz |
fix #14312
-rw-r--r-- | compiler/liftdestructors.nim | 15 | ||||
-rw-r--r-- | tests/arc/tcaseobj.nim | 15 |
2 files changed, 22 insertions, 8 deletions
diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index d70b968a8..2a7301f24 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -62,9 +62,18 @@ proc newAsgnStmt(le, ri: PNode): PNode = result[0] = le result[1] = ri +proc genBuiltin(g: ModuleGraph; magic: TMagic; name: string; i: PNode): PNode = + result = newNodeI(nkCall, i.info) + result.add createMagic(g, name, magic).newSymNode + result.add i + proc defaultOp(c: var TLiftCtx; t: PType; body, x, y: PNode) = if c.kind in {attachedAsgn, attachedDeepCopy, attachedSink}: body.add newAsgnStmt(x, y) + elif c.kind == attachedDestructor and c.addMemReset: + let call = genBuiltin(c.g, mDefault, "default", x) + call.typ = t + body.add newAsgnStmt(x, call) proc genAddr(g: ModuleGraph; x: PNode): PNode = if x.kind == nkHiddenDeref: @@ -74,12 +83,6 @@ proc genAddr(g: ModuleGraph; x: PNode): PNode = result = newNodeIT(nkHiddenAddr, x.info, makeVarType(x.typ.owner, x.typ)) result.add x - -proc genBuiltin(g: ModuleGraph; magic: TMagic; name: string; i: PNode): PNode = - result = newNodeI(nkCall, i.info) - result.add createMagic(g, name, magic).newSymNode - result.add i - proc genWhileLoop(c: var TLiftCtx; i, dest: PNode): PNode = result = newNodeI(nkWhileStmt, c.info, 2) let cmp = genBuiltin(c.g, mLtI, "<", i) diff --git a/tests/arc/tcaseobj.nim b/tests/arc/tcaseobj.nim index dd02675cc..107cf9fc1 100644 --- a/tests/arc/tcaseobj.nim +++ b/tests/arc/tcaseobj.nim @@ -194,8 +194,6 @@ proc test_myobject = test_myobject() - - #------------------------------------------------ # bug #14244 @@ -212,3 +210,16 @@ proc init(): RocksDBResult[string] = result.value = "ok" echo init() + + +#------------------------------------------------ +# bug #14312 + +type MyObj = object + case kind: bool + of false: x0: int # would work with a type like seq[int]; value would be reset + of true: x1: string + +var a = MyObj(kind: false, x0: 1234) +a.kind = true +doAssert(a.x1 == "") |