Initialize the target map when a StringToString flag has a nil default - #506
Merged
tomasaschan merged 2 commits intoSep 6, 2026
Merged
Conversation
stringToStringValue.Set wrote into *s.value directly, so a StringToString flag declared with a nil default map panicked with "assignment to entry in nil map" the first time it was set. Allocate the map when it is nil before merging parsed values, and cover the nil-default case in a test.
nikolauspschuetz
marked this pull request as ready for review
August 26, 2026 19:56
tomasaschan
approved these changes
Aug 28, 2026
Author
|
Lint here was the golangci-lint/Go 1.27 export-data breakage, not this change — merged master so #508 is in. Needs a workflow-run approval to go green. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
StringToStringflag declared with a nil default map panics withassignment to entry in nil mapthe first time it's set —stringToStringValue.Setwrites into*s.valuewithout allocating it.This allocates the map when it's nil before merging the parsed values, and adds a nil-default regression test.
Verified: the new test panics on current code and passes with the fix; the full
pflagsuite stays green.Developed with AI assistance (Claude Code); I directed, reviewed, and verified it locally.