Skip to content

fix: support uintptr in oneof and noneof value matching - #1657

Open
sergioperezcheco wants to merge 1 commit into
go-playground:masterfrom
sergioperezcheco:fix/oneof-uintptr-support
Open

sergioperezcheco wants to merge 1 commit into
go-playground:masterfrom
sergioperezcheco:fix/oneof-uintptr-support

Conversation

@sergioperezcheco

Copy link
Copy Markdown
Contributor

Problem

oneof / noneof panic with Bad field type uintptr when the field is a uintptr, while every other numeric validator in baked_in.go handles reflect.Uintptr alongside the fixed-width uint kinds — including eq. The same field currently passes gte=1 and eq=7 but panics on enum matching:

v := validator.New()
v.Var(uintptr(7), "eq=7")        // ok
v.Var(uintptr(7), "oneof=5 7 9") // panic: Bad field type uintptr

Fix

Add reflect.Uintptr to the existing uint case in isOneOf, matching the convention already used by the numeric comparisons, cross-field comparisons, and isPort in the same file. isNoneOf delegates to isOneOf. oneofci / noneofci remain string-only by contract.

Tests

  • uintptr pass/fail cases added to TestOneOfValidation and TestNoneOfValidation: list hit, list miss, and noneof miss-list.
  • go test -race -cover ./...: 25 packages pass, 96.8% coverage on the main package.
  • Public-API probes over Var, Struct, defined uintptr types, and pointer fields behave consistently with uint.

AI-assisted, disclosed per CONTRIBUTING.

Every numeric validator in baked_in.go already handles reflect.Uintptr
alongside the fixed-width uint kinds, so a uintptr field passes gte or
eq but panics with Bad field type uintptr on oneof/noneof. Format the
field the same way as other unsigned kinds so enum matching works
consistently.

Co-Authored-By: OpenAI GPT-6.1-Sol <noreply@openai.com>
Signed-off-by: sergioperezcheco <checo520@outlook.com>
@sergioperezcheco
sergioperezcheco requested a review from a team as a code owner October 1, 2026 07:15
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.

1 participant