Skip to content

Commit

Permalink
fixes #19401; fixes #19402; rework Forward declaration and finalizer …
Browse files Browse the repository at this point in the history
…for ORC
  • Loading branch information
ringabout committed Sep 2, 2022
1 parent 5211a47 commit 9788f85
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/semmagic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,15 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode,
getAttachedOp(c.graph, t, attachedDestructor).owner == fin:
discard "already turned this one into a finalizer"
else:
bindTypeHook(c, turnFinalizerIntoDestructor(c, fin, n.info), n, attachedDestructor)
if sfForward in fin.flags:
# todo change the name
let wrapperSym = newSym(skProc, getIdent(c.graph.cache, "wrapper_" & fin.name.s), nextSymId c.idgen, fin.owner, fin.info)
let wrapper = c.semExpr(c, newProcNode(nkProcDef, fin.info, body = newTree(nkCall, newSymNode(fin), fin.ast[paramsPos][1][0]),
params = fin.ast[paramsPos], name = newSymNode(wrapperSym), pattern = c.graph.emptyNode,
genericParams = c.graph.emptyNode, pragmas = c.graph.emptyNode, exceptions = c.graph.emptyNode), {})
bindTypeHook(c, turnFinalizerIntoDestructor(c, wrapperSym, wrapper.info), n, attachedDestructor)
else:
bindTypeHook(c, turnFinalizerIntoDestructor(c, fin, n.info), n, attachedDestructor)
result = n
of mDestroy:
result = n
Expand Down
13 changes: 13 additions & 0 deletions tests/arc/t19401.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
discard """
output: "delete foo"
matrix: "--mm:arc"
"""

type Foo = ref object
proc delete(self: Foo)
proc newFoo: Foo = new(result, delete)
proc delete(self: Foo) = echo("delete Foo")

if isMainModule:
proc test() = discard newFoo()
test()
13 changes: 13 additions & 0 deletions tests/arc/t19402.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
discard """
output: "delete foo"
matrix: "--mm:arc"
"""

type Foo = ref object of RootObj
proc delete(self: Foo)
proc newFoo: Foo = new(result, delete)
proc delete(self: Foo) = echo("delete Foo")

if isMainModule:
proc test() = discard newFoo()
test()

0 comments on commit 9788f85

Please sign in to comment.