hclsyntax: Allow the splat operators to be applied to sets

We automatically convert from set to list in many other situations, so for
consistency we should accept sets here too and just treat them as
unordered sequences.

This closes #30.
This commit is contained in:
Martin Atkins 2018-05-23 16:40:24 -07:00
parent 3006ab4459
commit 524cf10f48
2 changed files with 17 additions and 1 deletions

View File

@ -1170,7 +1170,7 @@ func (e *SplatExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
// both to tuples/lists and to other values, and in the latter case
// the value will be treated as an implicit single-value list. We'll
// deal with that here first.
if !(sourceVal.Type().IsTupleType() || sourceVal.Type().IsListType()) {
if !(sourceVal.Type().IsTupleType() || sourceVal.Type().IsListType() || sourceVal.Type().IsSetType()) {
sourceVal = cty.ListVal([]cty.Value{sourceVal})
}

View File

@ -733,6 +733,22 @@ upper(
}),
0,
},
{
`set.*.name`,
&hcl.EvalContext{
Variables: map[string]cty.Value{
"set": cty.SetVal([]cty.Value{
cty.ObjectVal(map[string]cty.Value{
"name": cty.StringVal("Steve"),
}),
}),
},
},
cty.TupleVal([]cty.Value{
cty.StringVal("Steve"),
}),
0,
},
{
`["hello", "goodbye"].*`,
nil,