Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

destructors: update, =destroy does not require a 'var T' #22168

Merged
merged 1 commit into from
Jun 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ written as:
len, cap: int
data: ptr UncheckedArray[T]

proc `=destroy`*[T](x: var myseq[T]) =
proc `=destroy`*[T](x: myseq[T]) =
if x.data != nil:
for i in 0..<x.len: `=destroy`(x.data[i])
dealloc(x.data)
Expand Down Expand Up @@ -256,10 +256,10 @@ The general pattern in using `=destroy` with `=trace` looks like:
Test[T](size: size, arr: cast[ptr UncheckedArray[T]](alloc0(sizeof(T) * size)))


proc `=destroy`[T](dest: var Test[T]) =
proc `=destroy`[T](dest: Test[T]) =
if dest.arr != nil:
for i in 0 ..< dest.size: dest.arr[i].`=destroy`
dest.arr.dealloc
dealloc dest.arr

proc `=trace`[T](dest: var Test[T]; env: pointer) =
if dest.arr != nil:
Expand Down