cmd/cloner: add regression test for slice nil/empty semantics

We had a misstep with the semantics when applying an optimization that
showed up in the roll into corp. This test ensures that case and related
cases must be retained.

Updates #9410
Updates #9601
Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
James Tucker
2023-09-29 18:31:45 -07:00
committed by James Tucker
parent e03f0d5f5c
commit ab810f1f6d
5 changed files with 131 additions and 1 deletions

View File

@@ -157,7 +157,11 @@ func (src *StructWithSlices) Clone() *StructWithSlices {
if src.Ints != nil {
dst.Ints = make([]*int, len(src.Ints))
for i := range dst.Ints {
dst.Ints[i] = ptr.To(*src.Ints[i])
if src.Ints[i] == nil {
dst.Ints[i] = nil
} else {
dst.Ints[i] = ptr.To(*src.Ints[i])
}
}
}
dst.Slice = append(src.Slice[:0:0], src.Slice...)