diff options
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/hclsyntax')
4 files changed, 58 insertions, 3 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression.go b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression.go index 26819a2..d3f7a74 100644 --- a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression.go +++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression.go | |||
@@ -473,8 +473,35 @@ func (e *ConditionalExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostic | |||
473 | falseResult, falseDiags := e.FalseResult.Value(ctx) | 473 | falseResult, falseDiags := e.FalseResult.Value(ctx) |
474 | var diags hcl.Diagnostics | 474 | var diags hcl.Diagnostics |
475 | 475 | ||
476 | // Try to find a type that both results can be converted to. | 476 | resultType := cty.DynamicPseudoType |
477 | resultType, convs := convert.UnifyUnsafe([]cty.Type{trueResult.Type(), falseResult.Type()}) | 477 | convs := make([]convert.Conversion, 2) |
478 | |||
479 | switch { | ||
480 | // If either case is a dynamic null value (which would result from a | ||
481 | // literal null in the config), we know that it can convert to the expected | ||
482 | // type of the opposite case, and we don't need to speculatively reduce the | ||
483 | // final result type to DynamicPseudoType. | ||
484 | |||
485 | // If we know that either Type is a DynamicPseudoType, we can be certain | ||
486 | // that the other value can convert since it's a pass-through, and we don't | ||
487 | // need to unify the types. If the final evaluation results in the dynamic | ||
488 | // value being returned, there's no conversion we can do, so we return the | ||
489 | // value directly. | ||
490 | case trueResult.RawEquals(cty.NullVal(cty.DynamicPseudoType)): | ||
491 | resultType = falseResult.Type() | ||
492 | convs[0] = convert.GetConversionUnsafe(cty.DynamicPseudoType, resultType) | ||
493 | case falseResult.RawEquals(cty.NullVal(cty.DynamicPseudoType)): | ||
494 | resultType = trueResult.Type() | ||
495 | convs[1] = convert.GetConversionUnsafe(cty.DynamicPseudoType, resultType) | ||
496 | case trueResult.Type() == cty.DynamicPseudoType, falseResult.Type() == cty.DynamicPseudoType: | ||
497 | // the final resultType type is still unknown | ||
498 | // we don't need to get the conversion, because both are a noop. | ||
499 | |||
500 | default: | ||
501 | // Try to find a type that both results can be converted to. | ||
502 | resultType, convs = convert.UnifyUnsafe([]cty.Type{trueResult.Type(), falseResult.Type()}) | ||
503 | } | ||
504 | |||
478 | if resultType == cty.NilType { | 505 | if resultType == cty.NilType { |
479 | return cty.DynamicVal, hcl.Diagnostics{ | 506 | return cty.DynamicVal, hcl.Diagnostics{ |
480 | { | 507 | { |
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_template.go b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_template.go index fa79e3d..ca3dae1 100644 --- a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_template.go +++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/expression_template.go | |||
@@ -89,6 +89,26 @@ func (e *TemplateExpr) StartRange() hcl.Range { | |||
89 | return e.Parts[0].StartRange() | 89 | return e.Parts[0].StartRange() |
90 | } | 90 | } |
91 | 91 | ||
92 | // IsStringLiteral returns true if and only if the template consists only of | ||
93 | // single string literal, as would be created for a simple quoted string like | ||
94 | // "foo". | ||
95 | // | ||
96 | // If this function returns true, then calling Value on the same expression | ||
97 | // with a nil EvalContext will return the literal value. | ||
98 | // | ||
99 | // Note that "${"foo"}", "${1}", etc aren't considered literal values for the | ||
100 | // purposes of this method, because the intent of this method is to identify | ||
101 | // situations where the user seems to be explicitly intending literal string | ||
102 | // interpretation, not situations that result in literals as a technicality | ||
103 | // of the template expression unwrapping behavior. | ||
104 | func (e *TemplateExpr) IsStringLiteral() bool { | ||
105 | if len(e.Parts) != 1 { | ||
106 | return false | ||
107 | } | ||
108 | _, ok := e.Parts[0].(*LiteralValueExpr) | ||
109 | return ok | ||
110 | } | ||
111 | |||
92 | // TemplateJoinExpr is used to convert tuples of strings produced by template | 112 | // TemplateJoinExpr is used to convert tuples of strings produced by template |
93 | // constructs (i.e. for loops) into flat strings, by converting the values | 113 | // constructs (i.e. for loops) into flat strings, by converting the values |
94 | // tos strings and joining them. This AST node is not used directly; it's | 114 | // tos strings and joining them. This AST node is not used directly; it's |
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/parser.go b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/parser.go index 253ad50..772ebae 100644 --- a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/parser.go +++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/parser.go | |||
@@ -853,6 +853,14 @@ Traversal: | |||
853 | SrcRange: rng, | 853 | SrcRange: rng, |
854 | } | 854 | } |
855 | ret = makeRelativeTraversal(ret, step, rng) | 855 | ret = makeRelativeTraversal(ret, step, rng) |
856 | } else if tmpl, isTmpl := keyExpr.(*TemplateExpr); isTmpl && tmpl.IsStringLiteral() { | ||
857 | litKey, _ := tmpl.Value(nil) | ||
858 | rng := hcl.RangeBetween(open.Range, close.Range) | ||
859 | step := hcl.TraverseIndex{ | ||
860 | Key: litKey, | ||
861 | SrcRange: rng, | ||
862 | } | ||
863 | ret = makeRelativeTraversal(ret, step, rng) | ||
856 | } else { | 864 | } else { |
857 | rng := hcl.RangeBetween(open.Range, close.Range) | 865 | rng := hcl.RangeBetween(open.Range, close.Range) |
858 | ret = &IndexExpr{ | 866 | ret = &IndexExpr{ |
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/spec.md b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/spec.md index 091c1c2..d7faeed 100644 --- a/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/spec.md +++ b/vendor/github.com/hashicorp/hcl2/hcl/hclsyntax/spec.md | |||
@@ -187,7 +187,7 @@ for later evaluation by the calling application. | |||
187 | ### Blocks | 187 | ### Blocks |
188 | 188 | ||
189 | A _block_ creates a child body that is annotated with a block _type_ and | 189 | A _block_ creates a child body that is annotated with a block _type_ and |
190 | zero or more block _labels_. Blocks create a structural hierachy which can be | 190 | zero or more block _labels_. Blocks create a structural hierarchy which can be |
191 | interpreted by the calling application. | 191 | interpreted by the calling application. |
192 | 192 | ||
193 | Block labels can either be quoted literal strings or naked identifiers. | 193 | Block labels can either be quoted literal strings or naked identifiers. |