Skip to content

Commit

Permalink
Merge pull request #429 from hashicorp/alisdair/argument-expansion-marks
Browse files Browse the repository at this point in the history
hclsyntax: Fix panic when expanding marked funargs
  • Loading branch information
alisdair authored Dec 10, 2020
2 parents d8c5050 + b857e80 commit c30c0c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hclsyntax/expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,17 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
return cty.DynamicVal, diags
}

// When expanding arguments from a collection, we must first unmark
// the collection itself, and apply any marks directly to the
// elements. This ensures that marks propagate correctly.
expandVal, marks := expandVal.Unmark()
newArgs := make([]Expression, 0, (len(args)-1)+expandVal.LengthInt())
newArgs = append(newArgs, args[:len(args)-1]...)
it := expandVal.ElementIterator()
for it.Next() {
_, val := it.Element()
newArgs = append(newArgs, &LiteralValueExpr{
Val: val,
Val: val.WithMarks(marks),
SrcRange: expandExpr.Range(),
})
}
Expand Down
17 changes: 17 additions & 0 deletions hclsyntax/expression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,23 @@ EOT
cty.NumberIntVal(1),
0,
},
{ // marked argument expansion
`min(xs...)`,
&hcl.EvalContext{
Functions: map[string]function.Function{
"min": stdlib.MinFunc,
},
Variables: map[string]cty.Value{
"xs": cty.ListVal([]cty.Value{
cty.NumberIntVal(3),
cty.NumberIntVal(1),
cty.NumberIntVal(4),
}).Mark("sensitive"),
},
},
cty.NumberIntVal(1).Mark("sensitive"),
0,
},
}

for _, test := range tests {
Expand Down

0 comments on commit c30c0c4

Please sign in to comment.