Skip to content

query: check IsZero before kind switch in isEmptyValue (#202) - #203

Open
Yshuro wants to merge 1 commit into
google:masterfrom
Yshuro:fix/iszero-named-types
Open

Yshuro wants to merge 1 commit into
google:masterfrom
Yshuro:fix/iszero-named-types

Conversation

@Yshuro

@Yshuro Yshuro commented Nov 19, 2026

Copy link
Copy Markdown

The documentation for Values states:

The empty values are false, 0, any nil pointer or interface value, any array,
slice, map, or string of length zero, and any type (such as time.Time) that
returns true for IsZero().

However, isEmptyValue evaluated the switch v.Kind() before checking the zeroable interface. As a result, named scalar types (such as ype Limit int) or named collection types (such as ype Tags []string) returning custom emptiness from IsZero() were handled by the kind switch instead, causing sentinel values like Limit(-1) or CustomString(unset) to be included in query parameters despite omitempty.

This change checks the zeroable interface (IsZero() bool) before the kind-specific switch, while preserving the immediate empty evaluation for nil pointer and interface values.

Fixes #202.

@google-cla

google-cla Bot commented Nov 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Signed-off-by: Sami Chergui <83331159+Yshuro@users.noreply.github.com>
@Yshuro
Yshuro force-pushed the fix/iszero-named-types branch from f83f17b to e635de9 Compare November 19, 2026 16:12
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.

query: omitempty ignores IsZero on named scalar and collection types

1 participant