fix: required flags aren't enforced when a default resolves to empty - #624
Open
james-lawrence wants to merge 2 commits into
Conversation
HasDefault is computed once in hydrateTag from the raw, uninterpolated
tag string, so a default like "${var}" looks non-empty even when var
is unset. checkMissingFlags only checks flag.Set, and Value.Parse sets
Set = true unconditionally when applying a default - so a required
field whose ${var}-templated default resolves to "" was silently
treated as satisfied instead of missing.
Recompute HasDefault in interpolateValue once Default is actually
resolved, after both Default and Enum have been interpolated. Skip
the demotion when "" is itself a declared enum member (enum:"one,two,")
since that's a legitimate, deliberately-chosen value rather than a
missing one.
alecthomas
approved these changes
Jul 18, 2026
alecthomas
left a comment
Owner
There was a problem hiding this comment.
LGTM with one requested change!
| // confusing "bool value must be true, 1, ..." error instead of a plain | ||
| // "required" one). | ||
| func TestRequiredFlagWithDefault(t *testing.T) { | ||
| // assert.Contains(err.Error(), "missing flags") rather than a bare |
Owner
There was a problem hiding this comment.
Can ytou strip all these verbose comments out please?
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.
Not sure how you want to handle this situation but, test cases + a potential fix:
HasDefault is computed once in hydrateTag from the raw, uninterpolated tag string, so a default like "${var}" looks non-empty even when var is unset. checkMissingFlags only checks flag.Set, and Value.Parse sets Set = true unconditionally when applying a default - so a required field whose ${var}-templated default resolves to "" was silently treated as satisfied instead of missing.
Recompute HasDefault in interpolateValue once Default is actually resolved, after both Default and Enum have been interpolated. Skip the demotion when "" is itself a declared enum member (enum:"one,two,") since that's a legitimate, deliberately-chosen value rather than a missing one.