fixes #19401; fixes #19402; rework Forward declaration and finalizer for ORC (#20295)

* fixes #19401; fixes #19402; rework Forward declaration and finalizer for ORC

* add more tests

* give it a name

* make more tests

* fixes tests

* hidden addr for cpp

* move code to a function
This commit is contained in:
ringabout 2022-09-28 02:07:26 +08:00 • committed by GitHub
commit 80e739f2bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 112 additions and 24 deletions

32
tests/arc/t19401.nim Normal file
View file

@ -0,0 +1,32 @@
discard """
output: '''
delete foo
delete foo
delete foo
'''
matrix: "--mm:arc"
"""
type Foo = ref object
data: int
proc delete(self: Foo)
proc newFoo: Foo =
let x = 12
discard x
new(result, delete)
result.data = x
proc delete(self: Foo) =
doAssert self.data == 12
echo("delete foo")
if isMainModule:
proc test() =
let x1 = newFoo()
let x2 = newFoo()
discard x1
discard x2
var x3: Foo
new(x3, delete)
x3.data = 12
discard x3
test()

32
tests/arc/t19402.nim Normal file
View file

@ -0,0 +1,32 @@
discard """
output: '''
delete foo
delete foo
delete foo
'''
matrix: "--mm:arc"
"""
type Foo = ref object of RootObj
data: int
proc delete(self: Foo)
proc newFoo: Foo =
let x = 12
discard x
new(result, delete)
result.data = x
proc delete(self: Foo) =
doAssert self.data == 12
echo("delete foo")
if isMainModule:
proc test() =
let x1 = newFoo()
let x2 = newFoo()
discard x1
discard x2
var x3: Foo
new(x3, delete)
x3.data = 12
discard x3
test()