fixes #15044 [backport:1.2]
This commit is contained in:
parent
14d16c2174
commit
c90c53e8bb
2 changed files with 23 additions and 3 deletions
|
|
@ -527,12 +527,14 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
|
||||||
if n[^1].kind == nkSym and n[^1].sym.kind notin {skProc, skFunc}:
|
if n[^1].kind == nkSym and n[^1].sym.kind notin {skProc, skFunc}:
|
||||||
localError(c.config, n.info, "finalizer must be a direct reference to a proc")
|
localError(c.config, n.info, "finalizer must be a direct reference to a proc")
|
||||||
elif optTinyRtti in c.config.globalOptions:
|
elif optTinyRtti in c.config.globalOptions:
|
||||||
|
let fin = if n[^1].kind == nkLambda: n[^1][namePos].sym
|
||||||
|
else: n[^1].sym
|
||||||
# check if we converted this finalizer into a destructor already:
|
# check if we converted this finalizer into a destructor already:
|
||||||
let t = whereToBindTypeHook(c, n[^1].sym.typ[1].skipTypes(abstractInst+{tyRef}))
|
let t = whereToBindTypeHook(c, fin.typ[1].skipTypes(abstractInst+{tyRef}))
|
||||||
if t != nil and t.attachedOps[attachedDestructor] != nil and t.attachedOps[attachedDestructor].owner == n[^1].sym:
|
if t != nil and t.attachedOps[attachedDestructor] != nil and t.attachedOps[attachedDestructor].owner == fin:
|
||||||
discard "already turned this one into a finalizer"
|
discard "already turned this one into a finalizer"
|
||||||
else:
|
else:
|
||||||
bindTypeHook(c, turnFinalizerIntoDestructor(c, n[^1].sym, n.info), n, attachedDestructor)
|
bindTypeHook(c, turnFinalizerIntoDestructor(c, fin, n.info), n, attachedDestructor)
|
||||||
result = n
|
result = n
|
||||||
of mDestroy:
|
of mDestroy:
|
||||||
result = n
|
result = n
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ whiley ends :(
|
||||||
0
|
0
|
||||||
new line before - @['a']
|
new line before - @['a']
|
||||||
new line after - @['a']
|
new line after - @['a']
|
||||||
|
finalizer
|
||||||
closed
|
closed
|
||||||
destroying variable: 20
|
destroying variable: 20
|
||||||
destroying variable: 10
|
destroying variable: 10
|
||||||
|
|
@ -258,6 +259,23 @@ newline.insert(indent, 0)
|
||||||
|
|
||||||
echo "new line after - ", newline
|
echo "new line after - ", newline
|
||||||
|
|
||||||
|
# bug #15044
|
||||||
|
|
||||||
|
type
|
||||||
|
Test = ref object
|
||||||
|
|
||||||
|
proc test: Test =
|
||||||
|
# broken
|
||||||
|
new(result, proc(x: Test) =
|
||||||
|
echo "finalizer"
|
||||||
|
)
|
||||||
|
|
||||||
|
proc tdirectFinalizer =
|
||||||
|
discard test()
|
||||||
|
|
||||||
|
tdirectFinalizer()
|
||||||
|
|
||||||
|
|
||||||
# bug #14480
|
# bug #14480
|
||||||
proc hello(): int =
|
proc hello(): int =
|
||||||
result = 42
|
result = 42
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue