states: Improve confusing comment for DeepCopy of local values
Some checks are pending
build / Build for freebsd_386 (push) Waiting to run
build / Build for linux_386 (push) Waiting to run
build / Build for openbsd_386 (push) Waiting to run
build / Build for windows_386 (push) Waiting to run
build / Build for freebsd_amd64 (push) Waiting to run
build / Build for linux_amd64 (push) Waiting to run
build / Build for openbsd_amd64 (push) Waiting to run
build / Build for solaris_amd64 (push) Waiting to run
build / Build for windows_amd64 (push) Waiting to run
build / Build for freebsd_arm (push) Waiting to run
build / Build for linux_arm (push) Waiting to run
build / Build for linux_arm64 (push) Waiting to run
build / Build for darwin_amd64 (push) Waiting to run
build / Build for darwin_arm64 (push) Waiting to run
build / End-to-end Tests for linux_386 (push) Waiting to run
build / End-to-end Tests for windows_386 (push) Waiting to run
build / End-to-end Tests for darwin_amd64 (push) Waiting to run
build / End-to-end Tests for linux_amd64 (push) Waiting to run
build / End-to-end Tests for windows_amd64 (push) Waiting to run
Quick Checks / List files changed for pull request (push) Waiting to run
Quick Checks / Unit tests for linux_386 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for windows_amd64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm (push) Blocked by required conditions
Quick Checks / Unit tests for darwin_arm64 (push) Blocked by required conditions
Quick Checks / Unit tests for linux_arm64 (push) Blocked by required conditions
Quick Checks / Race Tests (push) Blocked by required conditions
Quick Checks / End-to-end Tests (push) Blocked by required conditions
Quick Checks / Code Consistency Checks (push) Blocked by required conditions
Quick Checks / License Checks (push) Waiting to run
Website checks / List files changed for pull request (push) Waiting to run
Website checks / Build (push) Blocked by required conditions
Website checks / Test Installation Instructions (push) Blocked by required conditions

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 <mart@degeneration.co.uk>
This commit is contained in:
Martin Atkins 2026-04-01 11:18:49 -07:00
parent a803f4cc2f
commit ef4a93bb72

View file

@ -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),
}
}