hcl/hclsyntax: Return DynamicVal when splatting a DynamicVal

Since the result type from a splat is derived from the source value type,
we can't predict our result type when the source type isn't known.

Previously we were incorrectly returning cty.Tuple(cty.DynamicPseudoType)
in this case because of the automatic tuple promotion logic, but now we'll
correctly just give up even before we do _that_ when given a DynamicVal.
This commit is contained in:
Martin Atkins 2018-12-07 16:37:05 -08:00
parent df9794be1f
commit 6709268582
2 changed files with 16 additions and 0 deletions

View File

@ -1228,6 +1228,12 @@ 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

View File

@ -759,6 +759,16 @@ upper(
cty.UnknownVal(cty.Tuple([]cty.Type{cty.DynamicPseudoType})),
1, // a string has no attribute "name"
},
{
`dyn.*.name`,
&hcl.EvalContext{
Variables: map[string]cty.Value{
"dyn": cty.DynamicVal,
},
},
cty.DynamicVal,
0,
},
{
`unkobj.*.name`,
&hcl.EvalContext{