Files
Nim/tests/arc/tpartialtupleunpacking2.nim
metagn 8120d329ee generate let _ = to fully unpack partial tuple unpacking assignment for arc (#24948)
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.

(cherry picked from commit 71c5a4f72c)
2025-05-19 17:48:15 +02:00

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()