Merge pull request #434 from hashicorp/pselle/marked-keys

Error if attempting to use marked value as key
This commit is contained in:
Pam Selle 2020-12-17 10:33:49 -05:00 committed by GitHub
commit baa494e4a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -825,6 +825,19 @@ func (e *ObjectConsExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics
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
key, err = convert.Convert(key, cty.String)
if err != nil {

View File

@ -506,6 +506,19 @@ upper(
}),
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"}`,
&hcl.EvalContext{