Skip to content

fix: honor Equal methods on non-struct values - #72

Merged
daniel-nichter merged 1 commit into
go-test:mainfrom
guocn:fix/equal-method-non-struct-32
Oct 13, 2026
Merged

daniel-nichter merged 1 commit into
go-test:mainfrom
guocn:fix/equal-method-non-struct-32

Conversation

@guocn

@guocn guocn commented Oct 13, 2026 •

Copy link
Copy Markdown

fix: honor Equal methods on non-struct values

Fixes #32

Summary

  • Move the existing Equal-method dispatch out of the struct-only branch, after pointer/interface dereferencing and before kind-specific comparison.
  • Preserve existing error precedence, exported-field checks and embedded-method argument-type guard.
  • Add isolated regressions for net.IP's 4-byte versus 16-byte IPv4 representations (both argument orders) and a named string implementing case-insensitive Equal. Both also check unequal inputs.
  • Leave the existing test suite unchanged, following the maintainer's feedback on closed, unmerged PR refactor and improvements #49.

Tests

Using Go 1.26.9 linux/amd64 at /root/.hermes/cache/scratch/go/bin/go:

  • Upstream a1847fd plus new tests: go test -run '^TestEqualMethodOn' -count=1 -v ./... FAILS with expected IP representation and named-string diffs.
  • Fixed branch, same command: PASS.
  • go test -count=1 ./...: PASS.
  • go test -race -count=1 ./...: PASS.
  • go vet ./...: PASS.
  • git diff --cached --check: PASS.

Logs: ../logs/{before-fail,after-pass,suite,race,vet}.log

Contribution policy and duplication

README.md, SECURITY.md, LICENSE and tracked .github files were inspected. No CONTRIBUTING/AGENTS/AI policy is present; go-test/.github returned 404. Explicit AI acceptance is therefore UNKNOWN, not assumed. This patch and draft were prepared with AI assistance; a human should review and confirm maintainer acceptance before submission.

All available PRs (35, fitting one API page), current open PRs, issue comments, and PR #49 discussion were inspected. PR #49 previously attempted this fix in a broad refactor, was closed without merge, and its maintainer requested small isolated changes preserving the existing suite. Current open PR #71 concerns concurrent Differ support; its head deep.go still contains the same struct-only Equal dispatch and does not fix #32. No active matching implementation found.

Scope and limitations

Submitted as a draft for maintainer feedback; no deployment. No production systems changed. Only deep.go and equal_method_test.go belong to the commit.

Existing malformed Equal-method signature handling and pointer-receiver semantics are unchanged. This does not repair unrelated thread-safety of package-global configuration or cyclic graphs. Tests run on Linux amd64/Go 1.26.9 only, not the complete upstream OS/Go matrix. Independent reviewer subagent capability is unavailable in this delegated session; request parent/human review before publishing. New scalar regression was also verified against the pristine baseline after implementing the general dispatch move; the original IP regression was written and observed failing before any implementation changes.

Move the existing method dispatch before kind-specific comparison, preserving its exported-field and argument-type guards. Add regressions for net.IP representations and named scalar values.

Fixes go-test#32
@daniel-nichter
daniel-nichter marked this pull request as ready for review October 13, 2026 15:42
@daniel-nichter

Copy link
Copy Markdown
Member

Thank you for the fix, @guocn. I'll release in v1.1.2, which will put it in v1.2.0 too once that is released.

@daniel-nichter
daniel-nichter merged commit 8865dd0 into go-test:main Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

wrong comparison for slices types with Equal() method

3 participants