hclsyntax: null[*] to return an empty tuple
The rules for the splat operator call for it to return an empty tuple when its operand is null, but this rule was previously being overridden by another rule that a value whose type is unknown causes the operator to return an unknown value of unknown type. This was initially reported and discussed in Terraform, under hashicorp/terraform#26746.
This commit is contained in:
parent
9dabf7d816
commit
128a2f1879
@ -1320,12 +1320,6 @@ func (e *SplatExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
|
||||
}
|
||||
|
||||
sourceTy := sourceVal.Type()
|
||||
if sourceTy == cty.DynamicPseudoType {
|
||||
// If we don't even know the _type_ of our source value yet then
|
||||
// we'll need to defer all processing, since we can't decide our
|
||||
// result type either.
|
||||
return cty.DynamicVal, diags
|
||||
}
|
||||
|
||||
// A "special power" of splat expressions is that they can be applied
|
||||
// both to tuples/lists and to other values, and in the latter case
|
||||
@ -1349,6 +1343,13 @@ func (e *SplatExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
|
||||
return cty.DynamicVal, diags
|
||||
}
|
||||
|
||||
if sourceTy == cty.DynamicPseudoType {
|
||||
// If we don't even know the _type_ of our source value yet then
|
||||
// we'll need to defer all processing, since we can't decide our
|
||||
// result type either.
|
||||
return cty.DynamicVal, diags
|
||||
}
|
||||
|
||||
if autoUpgrade {
|
||||
sourceVal = cty.TupleVal([]cty.Value{sourceVal})
|
||||
sourceTy = sourceVal.Type()
|
||||
|
@ -907,6 +907,12 @@ upper(
|
||||
}),
|
||||
0,
|
||||
},
|
||||
{
|
||||
`null[*]`,
|
||||
nil,
|
||||
cty.EmptyTupleVal,
|
||||
0,
|
||||
},
|
||||
{
|
||||
`{name: "Steve"}[*].name`,
|
||||
nil,
|
||||
|
Loading…
Reference in New Issue
Block a user