mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
improvements for destructors
This commit is contained in:
21
tests/reject/tdestructor.nim
Normal file
21
tests/reject/tdestructor.nim
Normal file
@@ -0,0 +1,21 @@
|
||||
discard """
|
||||
line: 20
|
||||
errormsg: " usage of a type with a destructor in a non destructible context"
|
||||
"""
|
||||
|
||||
type
|
||||
TMyObj = object
|
||||
x, y: int
|
||||
p: pointer
|
||||
|
||||
proc destruct(o: var TMyObj) {.destructor.} =
|
||||
if o.p != nil: dealloc o.p
|
||||
|
||||
proc open: TMyObj =
|
||||
result = TMyObj(x: 1, y: 2, p: alloc(3))
|
||||
|
||||
|
||||
proc `$`(x: TMyObj): string = $x.y
|
||||
|
||||
echo open()
|
||||
|
||||
Reference in New Issue
Block a user