Assigning to a sink parameter that uses an instantiated generic tuple type creates an unsafe
shallow copy, which can lead to double frees, depending on the type.
Example
type
Object = object
val: int
Tuple[T] = (T,)
proc `=copy`(x: var Object, y: Object) =
echo "copied"
proc `=destroy`(x: var Object) =
if x.val != 0:
echo "destroyed: ", x.val
proc test(x: sink Tuple[Object]) =
var y: Tuple[Object]
y = x # last use of `x`, so this should move, or at least create a proper copy
test((Object(val: 1),))
Actual Output
destroyed: 1
destroyed: 1
Expected Output
destroyed: 1
Additional Information
removing the sink makes the issue go away (no destructor is called in that case)
Tuple not being generic also makes the issue go away
Assigning to a
sink
parameter that uses an instantiated generic tuple type creates an unsafe shallow copy, which can lead to double frees, depending on the type.Example
Actual Output
Expected Output
Additional Information
sink
makes the issue go away (no destructor is called in that case)Tuple
not being generic also makes the issue go away