if cap(r.back) > len(r.back) {
end := r.back[:len(r.back)+1][len(r.back)]
if !end.isEmpty() {
- panic("copies of a slog.Record were both modified")
+ // Don't panic; copy and muddle through.
+ r.back = slices.Clip(r.back)
+ r.back = append(r.back, String("!BUG", "AddAttrs unsafely called on copy of Record made without using Record.Clone"))
}
}
ne := countEmptyGroups(attrs[i:])
r1.back = b
// Make a copy that shares state.
r2 := r1
- // Adding to both should panic.
+ // Adding to both should insert a special Attr in the second.
+ r1AttrsBefore := attrsSlice(r1)
r1.AddAttrs(Int("p", 0))
- if !panics(func() { r2.AddAttrs(Int("p", 1)) }) {
- t.Error("expected panic")
- }
+ r2.AddAttrs(Int("p", 1))
+ check(r1, append(slices.Clip(r1AttrsBefore), Int("p", 0)))
r1Attrs := attrsSlice(r1)
+ check(r2, append(slices.Clip(r1AttrsBefore),
+ String("!BUG", "AddAttrs unsafely called on copy of Record made without using Record.Clone"), Int("p", 1)))
+
// Adding to a clone is fine.
r2 = r1.Clone()
check(r2, r1Attrs)