diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-05-21 20:53:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-21 14:53:08 +0200 |
commit | 309f97af4c03c2237a890aad147c261232b73acd (patch) | |
tree | bde054f2072a177e33719b96f17b2e93b48b30e3 /tests | |
parent | b838d3ece1e8530f355b5078b2daa96ac01acab5 (diff) | |
download | Nim-309f97af4c03c2237a890aad147c261232b73acd.tar.gz |
fixes #23627; Simple destructor code gives invalid C (#23631)
fixes #23627 ```nim type TestObj = object of RootObj TestTestObj = object of RootObj testo: TestObj proc `=destroy`(x: TestTestObj) = echo "Destructor for TestTestObj" proc testCaseT() = echo "\nTest Case T" let tt1 {.used.} = TestTestObj(testo: TestObj()) ``` When generating const object fields, it's likely that we need to generate type infos for the object, which may be an object with custom hooks. We need to generate potential consts in the hooks first. https://github.com/nim-lang/Nim/pull/20433 changed the semantics of initialization. It should evaluate`BracedInit` first.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/arc/tarcmisc.nim | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim index aef230334..88582303d 100644 --- a/tests/arc/tarcmisc.nim +++ b/tests/arc/tarcmisc.nim @@ -1,5 +1,6 @@ discard """ output: ''' +Destructor for TestTestObj =destroy called 123xyzabc destroyed: false @@ -36,9 +37,33 @@ destroying variable: 20 destroying variable: 10 closed ''' - cmd: "nim c --gc:arc --deepcopy:on -d:nimAllocPagesViaMalloc $file" + cmd: "nim c --mm:arc --deepcopy:on -d:nimAllocPagesViaMalloc $file" """ +block: # bug #23627 + type + TestObj = object of RootObj + + Test2 = object of RootObj + foo: TestObj + + TestTestObj = object of RootObj + shit: TestObj + + proc `=destroy`(x: TestTestObj) = + echo "Destructor for TestTestObj" + let test = Test2(foo: TestObj()) + + proc testCaseT() = + let tt1 {.used.} = TestTestObj(shit: TestObj()) + + + proc main() = + testCaseT() + + main() + + # bug #9401 type @@ -46,13 +71,12 @@ type len: int data: ptr UncheckedArray[float] -proc `=destroy`*(m: var MyObj) = +proc `=destroy`*(m: MyObj) = echo "=destroy called" if m.data != nil: deallocShared(m.data) - m.data = nil type MyObjDistinct = distinct MyObj @@ -104,7 +128,7 @@ bbb("123") type Variable = ref object value: int -proc `=destroy`(self: var typeof(Variable()[])) = +proc `=destroy`(self: typeof(Variable()[])) = echo "destroying variable: ",self.value proc newVariable(value: int): Variable = @@ -158,7 +182,7 @@ type B = ref object of A x: int -proc `=destroy`(x: var AObj) = +proc `=destroy`(x: AObj) = close(x.io) echo "closed" |