-
Notifications
You must be signed in to change notification settings - Fork 617
Consider typed, value-less variables to have null value
#3198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -282,7 +282,7 @@ func (p *parser) resolveValue(ectx *hcl.EvalContext, name string) (err error) { | |
| } | ||
|
|
||
| var diags hcl.Diagnostics | ||
| varType := cty.DynamicPseudoType | ||
| varType, typeSpecified := cty.DynamicPseudoType, false | ||
| def, ok := p.attrs[name] | ||
| if !ok { | ||
| vr, ok := p.vars[name] | ||
|
|
@@ -295,12 +295,13 @@ func (p *parser) resolveValue(ectx *hcl.EvalContext, name string) (err error) { | |
| if diags.HasErrors() { | ||
| return diags | ||
| } | ||
| typeSpecified = !varType.Equals(cty.DynamicPseudoType) || hcl.ExprAsKeyword(vr.Type) == "any" | ||
| } | ||
|
|
||
| if def == nil { | ||
| // lack of specified value is considered to have an empty string value, | ||
| // but any overrides get type checked | ||
| if _, ok, _ := p.valueHasOverride(name, false); !ok { | ||
| // Lack of specified value, when untyped is considered to have an empty string value. | ||
| // A typed variable with no value will result in (typed) nil. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In hindsight, I probably should have done an early return for the typed |
||
| if _, ok, _ := p.valueHasOverride(name, false); !ok && !typeSpecified { | ||
| vv := cty.StringVal("") | ||
| v = &vv | ||
| return | ||
|
|
@@ -322,9 +323,6 @@ func (p *parser) resolveValue(ectx *hcl.EvalContext, name string) (err error) { | |
| } | ||
| } | ||
|
|
||
| // Not entirely true... this doesn't differentiate between a user that specified 'any' | ||
| // and a user that specified nothing. But the result is the same; both are treated as strings. | ||
| typeSpecified := !varType.Equals(cty.DynamicPseudoType) | ||
| envv, hasEnv, jsonEnv := p.valueHasOverride(name, typeSpecified) | ||
| _, isVar := p.vars[name] | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just making sure that we do have a test that checks that without the
typethe value is empty string?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't appear so.
There's one that verifies it's not an error condition (ignoring the value):
buildx/bake/hcl_test.go
Lines 1568 to 1576 in ea2b702
But I actually think this one indirectly does so:
buildx/bake/bake_test.go
Lines 1989 to 2003 in ea2b702
I'm fairly sure that equality checks will not invoke coercion. I know the validation does (one of its defining features), but don't know whether it would coerce a
nullto an empty string. Seems unlikely, but can't say for sure.Do you want an explicit one just to be safe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes would be good
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed extra commit to add test for empty string if no type set