mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-04 12:07:51 +00:00
fixes #24947 When injectdestructors detects that a variable is a tuple unpacking temp (i.e. it is an `skTemp`, is not a cursor, and has tuple type) it does not generate a destructor for it and only generates sink/bit assignments for its components. However the reason it does not generate a destructor is that it expects it to be fully unpacked, this is true for unpackings in for loops but not for tuple unpacking assignments which supports `_` since #22537. Tuple unpacking definitions for `var`/`let`/`const` do not generate `skTemp` and use the same symbol kind as the definition so they did not have this problem. To keep this compatible, the `_` parts of the tuple unpacking assignments are now not ignored and unpacked into `let _ = ...`, which generates its own destructor. Another option might be to use `skLet` instead of `skTemp` but this might cause changes to behavior like additional copies, I am not sure about this though.
19 lines
211 B
Nim
19 lines
211 B
Nim
discard """
|
|
output: '''
|
|
destroyed
|
|
'''
|
|
"""
|
|
|
|
# issue #24947
|
|
|
|
type Foo = object
|
|
|
|
proc `=destroy`(x: Foo) =
|
|
echo "destroyed"
|
|
|
|
proc go(): void =
|
|
let a = (1,2,3, Foo())
|
|
let (b,c,d,_) = a # let unpacking
|
|
|
|
go()
|