Skip to content

assert: compare values loaded from atomic pointers - #1989

Open
SAY-5 wants to merge 1 commit into
stretchr:masterfrom
SAY-5:fix/atomic-pointer-equality-1403
Open

SAY-5 wants to merge 1 commit into
stretchr:masterfrom
SAY-5:fix/atomic-pointer-equality-1403

Conversation

@SAY-5

@SAY-5 SAY-5 commented Oct 15, 2026

Copy link
Copy Markdown

Summary

Fix assert.Equal reporting distinct atomic pointers to equal values as unequal.

Changes

  • Compare values loaded from top-level pointers to the same instantiated sync/atomic.Pointer type, preserving nil and pointer-identity behavior.
  • Keep ordinary and unsafe-pointer behavior unchanged; only the standard atomic Load method is invoked.
  • Guard the implementation with go1.19 and provide an older-Go fallback without changing the Go 1.17 module requirement.
  • Add regression, boundary, cycle, and concurrent-store tests. Generic tests use a go1.21 build tag to retain compatibility with the module's older language version.

The original 14-case regression fails only the reported atomic case before the fix and passes afterward. The full module race suite, go vet ./..., generation, and formatting pass on Go 1.26.2/macOS arm64. The same 14-case external consumer passes with the actual Go 1.19.13 compiler/runtime and default vet/linking. The broader Go-version matrix was not run locally and remains for CI.

Motivation

Equal documents equality of referenced values. Two *atomic.Pointer[int] values holding distinct pointers to equal integers currently fail that comparison. This implements the atomic-pointer behavior requested in #1403 while retaining the maintainer's restriction against dereferencing unsafe.Pointer.

Example usage

one, anotherOne := 1, 1
var left, right atomic.Pointer[int]
left.Store(&one)
right.Store(&anotherOne)
assert.Equal(t, &left, &right)

Related issues

Fixes #1403.

OpenAI Codex assisted with the implementation and tests; a separate Codex agent reviewed the patch and verification evidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Equal values referenced via atomic.Pointer always fail Equal()

1 participant