* fixes #12883 * fix comment * add normalize * fix
This commit is contained in:
parent
777c9ad0ef
commit
12d2b980e8
2 changed files with 47 additions and 1 deletions
|
|
@ -758,6 +758,19 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
if n[1].typ.len > 0:
|
if n[1].typ.len > 0:
|
||||||
createTypeBoundOps(tracked, n[1].typ.lastSon, n.info)
|
createTypeBoundOps(tracked, n[1].typ.lastSon, n.info)
|
||||||
createTypeBoundOps(tracked, n[1].typ, n.info)
|
createTypeBoundOps(tracked, n[1].typ, n.info)
|
||||||
|
|
||||||
|
if a.kind == nkSym and a.sym.name.s.len > 0 and a.sym.name.s[0] == '=' and
|
||||||
|
tracked.owner.kind != skMacro:
|
||||||
|
let opKind = find(AttachedOpToStr, a.sym.name.s.normalize)
|
||||||
|
if opKind != -1:
|
||||||
|
# rebind type bounds operations after createTypeBoundOps call
|
||||||
|
let t = n[1].typ.skipTypes({tyAlias, tyVar})
|
||||||
|
if a.sym != t.attachedOps[TTypeAttachedOp(opKind)]:
|
||||||
|
createTypeBoundOps(tracked, t, n.info)
|
||||||
|
let op = t.attachedOps[TTypeAttachedOp(opKind)]
|
||||||
|
if op != nil:
|
||||||
|
n[0].sym = op
|
||||||
|
|
||||||
for i in 0..<n.safeLen:
|
for i in 0..<n.safeLen:
|
||||||
track(tracked, n[i])
|
track(tracked, n[i])
|
||||||
of nkDotExpr:
|
of nkDotExpr:
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,13 @@ destroy
|
||||||
destroy Foo: 123
|
destroy Foo: 123
|
||||||
destroy Foo: 5
|
destroy Foo: 5
|
||||||
(x1: (val: ...))
|
(x1: (val: ...))
|
||||||
destroy'''
|
destroy
|
||||||
|
---------------
|
||||||
|
app begin
|
||||||
|
(val: ...)
|
||||||
|
destroy
|
||||||
|
app end
|
||||||
|
'''
|
||||||
joinable: false
|
joinable: false
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -93,3 +99,30 @@ proc test =
|
||||||
echo obj2
|
echo obj2
|
||||||
|
|
||||||
test()
|
test()
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------
|
||||||
|
# Issue #12883
|
||||||
|
|
||||||
|
type
|
||||||
|
TopObject = object
|
||||||
|
internal: UniquePtr[int]
|
||||||
|
|
||||||
|
proc deleteTop(p: ptr TopObject) =
|
||||||
|
if p != nil:
|
||||||
|
`=destroy`(p[]) # !!! this operation used to leak the integer
|
||||||
|
deallocshared(p)
|
||||||
|
|
||||||
|
proc createTop(): ptr TopObject =
|
||||||
|
result = cast[ptr TopObject](allocShared0(sizeof(TopObject)))
|
||||||
|
result.internal = newUniquePtr(1)
|
||||||
|
|
||||||
|
proc test2() =
|
||||||
|
let x = createTop()
|
||||||
|
echo $x.internal
|
||||||
|
deleteTop(x)
|
||||||
|
|
||||||
|
echo "---------------"
|
||||||
|
echo "app begin"
|
||||||
|
test2()
|
||||||
|
echo "app end"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue