Error if attempting to use marked value as key
When evaluating an HCL expression attempting to use a marked value as an object key, return an error rather than falling through to the cty panic. The error style mimics similar errors in the area.
This commit is contained in:
parent
8045083719
commit
c227eb4f81
@ -825,6 +825,19 @@ func (e *ObjectConsExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if key.IsMarked() {
|
||||||
|
diags = append(diags, &hcl.Diagnostic{
|
||||||
|
Severity: hcl.DiagError,
|
||||||
|
Summary: "Marked value as key",
|
||||||
|
Detail: "Can't use a marked value as a key.",
|
||||||
|
Subject: item.ValueExpr.Range().Ptr(),
|
||||||
|
Expression: item.KeyExpr,
|
||||||
|
EvalContext: ctx,
|
||||||
|
})
|
||||||
|
known = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
key, err = convert.Convert(key, cty.String)
|
key, err = convert.Convert(key, cty.String)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -506,6 +506,19 @@ upper(
|
|||||||
}),
|
}),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Marked values as object keys
|
||||||
|
`{(var.greeting) = "world", "goodbye" = "earth"}`,
|
||||||
|
&hcl.EvalContext{
|
||||||
|
Variables: map[string]cty.Value{
|
||||||
|
"var": cty.ObjectVal(map[string]cty.Value{
|
||||||
|
"greeting": cty.StringVal("hello").Mark("marked"),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
cty.DynamicVal,
|
||||||
|
1,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
`{"${var.greeting}" = "world"}`,
|
`{"${var.greeting}" = "world"}`,
|
||||||
&hcl.EvalContext{
|
&hcl.EvalContext{
|
||||||
|
Loading…
Reference in New Issue
Block a user