diff options
author | Araq <rumpf_a@web.de> | 2019-09-10 09:40:53 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-09-10 09:43:37 +0200 |
commit | cf99c9bfb5b2e27612acebc0ddbfeb142bb1bb41 (patch) | |
tree | 4899b88819794fc6aec0735dea168a02e78aaf97 | |
parent | d363eced3a315ca4e06f2cf3ceef51a04fa74a78 (diff) | |
download | Nim-cf99c9bfb5b2e27612acebc0ddbfeb142bb1bb41.tar.gz |
fixes #12051
-rw-r--r-- | compiler/liftdestructors.nim | 10 | ||||
-rw-r--r-- | compiler/seminst.nim | 2 | ||||
-rw-r--r-- | tests/destructor/tnewruntime_misc.nim | 23 |
3 files changed, 31 insertions, 4 deletions
diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 3574adca0..14bbc3ba7 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -182,8 +182,16 @@ proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode; body.add newAsgnCall(c.g, op, x, y) result = true -proc addDestructorCall(c: var TLiftCtx; t: PType; body, x: PNode) = +proc addDestructorCall(c: var TLiftCtx; orig: PType; body, x: PNode) = + let t = orig.skipTypes(abstractInst) var op = t.destructor + + if op != nil and sfOverriden in op.flags: + if op.ast[genericParamsPos].kind != nkEmpty: + # patch generic destructor: + op = instantiateGeneric(c, op, t, t.typeInst) + t.attachedOps[attachedDestructor] = op + if op == nil and useNoGc(c, t): op = produceSym(c.g, c.c, t, attachedDestructor, c.info) doAssert op != nil diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 43aa08818..0a8a3c3af 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -387,7 +387,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, if c.inGenericContext == 0: instantiateBody(c, n, fn.typ.n, result, fn) sideEffectsCheck(c, result) - if result.magic != mSlice: + if result.magic notin {mSlice, mTypeOf}: # 'toOpenArray' is special and it is allowed to return 'openArray': paramsTypeCheck(c, result.typ) else: diff --git a/tests/destructor/tnewruntime_misc.nim b/tests/destructor/tnewruntime_misc.nim index 8abf0d30b..e6be5824d 100644 --- a/tests/destructor/tnewruntime_misc.nim +++ b/tests/destructor/tnewruntime_misc.nim @@ -4,7 +4,10 @@ discard """ Indeed axc (v: 10) -0 new: 0''' +0 new: 0 +... +destroying GenericObj[T] GenericObj[system.int] +''' """ import core / allocators @@ -92,9 +95,25 @@ type x: seq[(A, B)] -proc toTable[A,B](p: sink openArray[(A, B)]): Table[A, B] = +proc toTable[A,B](p: sink openArray[(A, B)]): Table[A, B] = for zz in mitems(p): result.x.add move(zz) let table = {"a": new(int)}.toTable() + +# bug # #12051 + +type + GenericObj[T] = object + val: T + Generic[T] = owned ref GenericObj[T] + +proc `=destroy`[T](x: var GenericObj[T]) = + echo "destroying GenericObj[T] ", x.typeof # to know when its being destroyed + +proc main12() = + let gnrc = Generic[int](val: 42) + echo "..." + +main12() |