fixes #12051
This commit is contained in:
parent
d363eced3a
commit
cf99c9bfb5
3 changed files with 31 additions and 4 deletions
|
|
@ -182,8 +182,16 @@ proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode;
|
||||||
body.add newAsgnCall(c.g, op, x, y)
|
body.add newAsgnCall(c.g, op, x, y)
|
||||||
result = true
|
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
|
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):
|
if op == nil and useNoGc(c, t):
|
||||||
op = produceSym(c.g, c.c, t, attachedDestructor, c.info)
|
op = produceSym(c.g, c.c, t, attachedDestructor, c.info)
|
||||||
doAssert op != nil
|
doAssert op != nil
|
||||||
|
|
|
||||||
|
|
@ -387,7 +387,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||||
if c.inGenericContext == 0:
|
if c.inGenericContext == 0:
|
||||||
instantiateBody(c, n, fn.typ.n, result, fn)
|
instantiateBody(c, n, fn.typ.n, result, fn)
|
||||||
sideEffectsCheck(c, result)
|
sideEffectsCheck(c, result)
|
||||||
if result.magic != mSlice:
|
if result.magic notin {mSlice, mTypeOf}:
|
||||||
# 'toOpenArray' is special and it is allowed to return 'openArray':
|
# 'toOpenArray' is special and it is allowed to return 'openArray':
|
||||||
paramsTypeCheck(c, result.typ)
|
paramsTypeCheck(c, result.typ)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@ discard """
|
||||||
Indeed
|
Indeed
|
||||||
axc
|
axc
|
||||||
(v: 10)
|
(v: 10)
|
||||||
0 new: 0'''
|
0 new: 0
|
||||||
|
...
|
||||||
|
destroying GenericObj[T] GenericObj[system.int]
|
||||||
|
'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import core / allocators
|
import core / allocators
|
||||||
|
|
@ -98,3 +101,19 @@ proc toTable[A,B](p: sink openArray[(A, B)]): Table[A, B] =
|
||||||
|
|
||||||
|
|
||||||
let table = {"a": new(int)}.toTable()
|
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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue