From ef4a93bb7233d409bafbc3bd82217463749bb2d1 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 1 Apr 2026 11:18:49 -0700 Subject: [PATCH] states: Improve confusing comment for DeepCopy of local values The comment here was trying to say that we don't need to _deep-copy_ cty.Value values, but it wasn't clear about that and so it seemed weird to have a comment saying that copying isn't needed right before a call to a function called "Copy". This updates the comment to be more explicit, and also takes the opportunity to simplify to use maps.Clone instead of maps.Copy, since we have no need for the intermediate empty map we were previously creating prior to the Copy call. Signed-off-by: Martin Atkins --- internal/states/state_deepcopy.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/states/state_deepcopy.go b/internal/states/state_deepcopy.go index 0573baaceb..1eda13798e 100644 --- a/internal/states/state_deepcopy.go +++ b/internal/states/state_deepcopy.go @@ -62,15 +62,14 @@ func (ms *Module) DeepCopy() *Module { for k, v := range ms.OutputValues { outputValues[k] = v.DeepCopy() } - localValues := make(map[string]cty.Value, len(ms.LocalValues)) - // cty.Value is immutable, so we don't need to copy these. - maps.Copy(localValues, ms.LocalValues) return &Module{ Addr: ms.Addr, // technically mutable, but immutable by convention Resources: resources, OutputValues: outputValues, - LocalValues: localValues, + + // [cty.Value] is immutable, so a shallow copy is okay for local values. + LocalValues: maps.Clone(ms.LocalValues), } }