Merge pull request #434 from hashicorp/pselle/marked-keys
Error if attempting to use marked value as key
This commit is contained in:
commit
baa494e4a8
@ -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