mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-20 22:35:24 +00:00
more destructor based changes (#10885)
* mark user defined destructors with sfOverriden to simplify the logic * refactoring in preparation to merge liftings and generic instantiations for destructors * ast: introduce nkHiddenTryStmt for destructor generation in order to be able to optimize better the code later on * renamed 'patterns' switch to 'trmacros' as it was totally misleading before * destructors: introduce tfCheckedForDestructor flag in preparation of strict =destroy checking * test for invalid/too late destructor introductions * liftdestructors: make code robust for nimsuggest * --newruntime works for hello world again * newruntime: code generation for closures
This commit is contained in:
15
tests/destructor/tinvalid_rebind.nim
Normal file
15
tests/destructor/tinvalid_rebind.nim
Normal file
@@ -0,0 +1,15 @@
|
||||
discard """
|
||||
joinable: false
|
||||
cmd: "nim check $file"
|
||||
errormsg: "cannot bind another '=destroy' to: Foo; previous declaration was constructed here implicitly: tinvalid_rebind.nim(12, 7)"
|
||||
line: 14
|
||||
"""
|
||||
|
||||
type
|
||||
Foo[T] = object
|
||||
|
||||
proc main =
|
||||
var f: Foo[int]
|
||||
|
||||
proc `=destroy`[T](f: var Foo[T]) =
|
||||
discard
|
||||
@@ -22,6 +22,7 @@ var
|
||||
|
||||
proc `=destroy`*[T](x: var opt[T]) =
|
||||
if x.data != nil:
|
||||
mixin `=destroy`
|
||||
when not supportsCopyMem(T):
|
||||
`=destroy`(x.data[])
|
||||
dealloc(x.data)
|
||||
|
||||
Reference in New Issue
Block a user