Skip to content

out-of-the-box support for atomic.Pointer #326

Open
@pohly

Description

@pohly

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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions