Skip to content

Fix type identification and mismatch checks for text flags - #526

Merged
tomasaschan merged 1 commit into
spf13:masterfrom
dewanshshekhar:fix/text-flag-type-check
Oct 20, 2026
Merged

tomasaschan merged 1 commit into
spf13:masterfrom
dewanshshekhar:fix/text-flag-type-check

Conversation

@dewanshshekhar

Copy link
Copy Markdown

Text flags currently use reflect.Type.Name() on their pointer values. Pointers are unnamed, so a *time.Time flag reports an empty type and GetText also accepts an unrelated pointer implementing encoding.TextUnmarshaler. That output can be modified instead of receiving the intended type-mismatch error.

Use reflect.Type.String() consistently for the flag and requested output type. This also gives text flags a usable type label, such as *time.Time, in help output. Add regressions for the label and for rejecting a different output type without modifying it; the existing time round-trip tests continue to pass.

Validation on Go 1.27.2, Windows amd64:

  • Both new regression tests fail before the production change.
  • go test -p 2 -count=1 ./... passes.
  • go vet -p 2 ./..., gofmt, and git diff --check pass.
  • Race testing was not run locally: this machine has CGO disabled and no C compiler. The existing CI matrix can cover it.

Prepared and tested with OpenAI Codex assistance. This is a draft for human review.

@CLAassistant

CLAassistant commented Oct 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@dewanshshekhar
dewanshshekhar marked this pull request as ready for review October 19, 2026 20:16
@tomasaschan
tomasaschan merged commit d26a4dc into spf13:master Oct 20, 2026
8 checks passed
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.

3 participants