diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-07-03 03:04:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-02 21:04:48 +0200 |
commit | 57296a51397d65ce4f342d6cbc92a9de2629875c (patch) | |
tree | df42f7ff238ca252347383312ae5b8ac2df0ec11 /tests/destructor/tnonvardestructor.nim | |
parent | 83a5865024cf391137fcbd4e5ed195cda969ed88 (diff) | |
download | Nim-57296a51397d65ce4f342d6cbc92a9de2629875c.tar.gz |
fixes #22197; Distinct ref objects + destructor cause C++ codegen error (#22207)
Diffstat (limited to 'tests/destructor/tnonvardestructor.nim')
-rw-r--r-- | tests/destructor/tnonvardestructor.nim | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/destructor/tnonvardestructor.nim b/tests/destructor/tnonvardestructor.nim index e482ba137..1f59a3978 100644 --- a/tests/destructor/tnonvardestructor.nim +++ b/tests/destructor/tnonvardestructor.nim @@ -192,4 +192,29 @@ block: doAssert $(x[]) == "()" # bug #11705 - foo() \ No newline at end of file + foo() + +block: # bug #22197 + type + H5IdObj = object + H5Id = ref H5IdObj + + FileID = distinct H5Id + + H5GroupObj = object + file_id: FileID + H5Group = ref H5GroupObj + + ## This would make it work! + #proc `=destroy`*(x: FileID) = `=destroy`(cast[H5Id](x)) + ## If this does not exist, it also works! + proc newFileID(): FileID = FileID(H5Id()) + + proc `=destroy`(grp: var H5GroupObj) = + ## Closes the group and resets all references to nil. + if cast[pointer](grp.fileId) != nil: + `=destroy`(grp.file_id) + + var grp = H5Group() + reset(grp.file_id) + reset(grp) |