Open
Description
Suppose a struct contains an atomic.Pointer instead of a normal pointer:
import "sync/atomic"
type A struct {
Ptr atomic.Pointer[int]
}
Using cmp.Diff
for such struct instances fails because the Pointer
type contains unexported fields:
panic: cannot handle unexported field at {*main.A}.Ptr.v:
"sync/atomic".Pointer[int]
consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported
See https://go.dev/play/p/Jp91WpSKFRx for a full example.
It would be nice if cmp.Diff
automatically did the same thing for atomic.Pointer
as it does for normal pointers: compare the value that is being pointed to.
The argument for such special support is two-fold:
- atomic.Pointer is part of the Go standard library.
- Doing it via a Transformer for
atomic.Pointer
is impossible without copying that value, which correctly fails the "go vet"copylocks
check. See https://github.com/kubernetes/kubernetes/pull/115777/files#diff-9b169e646cb953f34c0362a885d844daea86f5bef52012cb3af974f176bb281f and take address of field for comparison #310 (comment).