Fix destructor injections for global variables (#11230)
* attach global destructors at end of mainModule * Add testcase * Minor cleanup * Inject topLevelVar temporaries' destructors early * Fix megatest
This commit is contained in:
parent
a3e27ffa2c
commit
0c869eaa47
7 changed files with 45 additions and 8 deletions
8
tests/destructor/objFile.nim
Normal file
8
tests/destructor/objFile.nim
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
type Obj* = object
|
||||
v*: int
|
||||
|
||||
proc `=destroy`(this: var Obj) =
|
||||
echo "igotdestroyed"
|
||||
this.v = -1
|
||||
|
||||
var test* = Obj(v: 42)
|
||||
|
|
@ -6,6 +6,7 @@ discard """
|
|||
10
|
||||
destroyed!
|
||||
'''
|
||||
joinable: false
|
||||
"""
|
||||
|
||||
type
|
||||
|
|
|
|||
9
tests/destructor/tglobaldestructor.nim
Normal file
9
tests/destructor/tglobaldestructor.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
output: '''(v: 42)
|
||||
igotdestroyed'''
|
||||
"""
|
||||
|
||||
import objFile
|
||||
|
||||
echo test
|
||||
|
|
@ -3,6 +3,7 @@ discard """
|
|||
output: '''5
|
||||
vseq destroy
|
||||
'''
|
||||
joinable: false
|
||||
"""
|
||||
type
|
||||
opt*[T] = object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue