more arc features (#13098)
* config update * ARC now supports 'repr' and 'new' with finalizers is supported
This commit is contained in:
parent
c0973d1b47
commit
767592a3c3
7 changed files with 252 additions and 13 deletions
25
tests/destructor/tfinalizer.nim
Normal file
25
tests/destructor/tfinalizer.nim
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
discard """
|
||||
cmd: "nim c --gc:arc $file"
|
||||
output: '''Foo(field: "Dick Laurent", k: ka, x: 0.0)
|
||||
Dick Laurent is dead'''
|
||||
"""
|
||||
|
||||
type
|
||||
Kind = enum
|
||||
ka, kb
|
||||
Foo = ref object
|
||||
field: string
|
||||
case k: Kind
|
||||
of ka: x: float
|
||||
of kb: discard
|
||||
|
||||
#var x = Foo(field: "lovely")
|
||||
proc finalizer(x: Foo) =
|
||||
echo x.field, " is dead"
|
||||
|
||||
var x: Foo
|
||||
new(x, finalizer)
|
||||
x.field = "Dick Laurent"
|
||||
# reference to a great movie. If you haven't seen it, highly recommended.
|
||||
|
||||
echo repr x
|
||||
Loading…
Add table
Add a link
Reference in a new issue