Repository navigation
Compare native text flag type identities in GetText - #529
kimjooyoon wants to merge 1 commit into
Conversation
Use reflect.Type equality for TextVar values instead of treating their display names as unique identities. Preserve the existing type-label behavior for custom Value implementations and keep help labels unchanged. Add identical-name mismatch and matching/wrapped-value regression coverage. Prepared and tested with Codex assistance.
|
I'm curious: did you actually run into this bug, or did you send your agent to find weird edge cases in open-source libraries and patch them? |
|
It was the latter: the Codex agent found this edge case while investigating type checks in In plain terms, the old check compares the printed names of two types. Two separately declared Go types can have the same printed name while still being different types. In the reproducer, both are called The proposed change compares actual type identities for pflag's built-in text value. Custom/wrapped values keep the existing label-based behaviour. The agent prepared the patch and tests; the PR records its before/after checks. The Playground example shows the original behaviour without a local setup. I don't have evidence that this occurs frequently in real applications. My reason for proposing it is that the type check silently accepts a different type, and the fix is small. This reply was also drafted with Codex assistance. |
Follow-up to #526:
GetTextcan still accept a different native text type when two distinct Go types have identical display names. The regression uses two separately declaredstamptypes embeddingtime.Time. Theirreflect.Typevalues differ, but theirString()results agree. A cross-typeGetTextcurrently returns nil and overwrites the output timestamp instead of rejecting it.Run the four native type combinations in Go Playground without installing anything. It pins the original development commit and reproduces both cross-type overwrites on hosted Go 1.27.3; it does not run the proposed patch. Pinned source, original remote response and separate local patch observations retain source/runtime identities and an integrity checker.
Compare the actual
reflect.Typevalues for pflag's nativetextValue. KeepType()and help labels unchanged, and preserve the existing type-label contract for custom/wrappedValueimplementations. The Go reflect documentation explicitly distinguishes display strings from type identity.Both cross-type combinations fail on main
d26a4dcdand pass after the fix, with the rejected output preserved. Both same-type combinations and a wrapped custom-value round trip continue to pass. No helper packages or dependencies are added.Validation on Go 1.27.3, macOS arm64:
go test -count=1 ./...go test -race -count=1 ./...go build ./...go vet ./...golangci-lint v2.15.0 run --timeout 2m— 0 issuesgofmtandgit diff --checkThe upstream Go-version CI matrix remains separate from these local checks.
AI disclosure: a Codex agent prepared the patch, tests and this description, and ran the listed validation. No human-only review or upstream acceptance is implied.