Skip to content

docs: clarify assert.Zero() is unrelated to encoding/json omitempty/omitzero#1903

Open
RichardHopperProGrammar wants to merge 2 commits into
stretchr:masterfrom
RichardHopperProGrammar:fix/zero-doc-iszero
Open

docs: clarify assert.Zero() is unrelated to encoding/json omitempty/omitzero#1903
RichardHopperProGrammar wants to merge 2 commits into
stretchr:masterfrom
RichardHopperProGrammar:fix/zero-doc-iszero

Conversation

@RichardHopperProGrammar
Copy link
Copy Markdown

@RichardHopperProGrammar RichardHopperProGrammar commented May 27, 2026

Clarify that assert.Zero() is unrelated to encoding/json omitempty/omitzero

Summary

Update the documentation for assert.Zero() to explicitly clarify that it checks whether a value equals its zero value in Go, and is not related to Go 1.24+ encoding/json omitempty or omitzero semantics.

This is a common point of confusion — users expect assert.Zero() to behave like json.Marshal omitempty logic, but it simply checks equality against the type's zero value (== false, == "", == 0, etc.).

Related

  • Fixes #1759 — user confusion about assert.Zero() and omitzero semantics
  • Thanks to @ccoVeille for pointing out the related issue

Changes

  • Updated doc comment on Zero() function with explicit note about json omitempty/omitzero distinction

[ ] By checking this box, the PR author affirms that they have read and agree to the Code of Conduct and Contributing Guide.

assert.Zero uses reflect.Zero to compare against the zero value of
a type. It does not use or check any IsZero() method, and is unrelated
to encoding/json's omitempty or omitzero struct tags.

This change adds documentation to assert.Zero() to prevent confusion
and includes a test with an IsZero()-implementing struct to verify
the behavior.

Closes stretchr#1759
@ccoVeille
Copy link
Copy Markdown
Collaborator

ccoVeille commented May 28, 2026

Your fix is related to an issue I raised

You can mention it in your PR description

ccoVeille
ccoVeille previously approved these changes May 28, 2026
@RichardHopperProGrammar
Copy link
Copy Markdown
Author

Thanks @ccoVeille — updated the PR description to reference #1759 and added context about the confusion. Appreciate the link!

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.

document that encoding/json omitzero/IsZero is not about assert.IsZero/reflect.Zero

2 participants