hclsyntax: Highlight key expression on invalid key type in object cons

Previously we were incorrectly indicating the value expression as the
problem.

This fixes #54.
This commit is contained in:
Martin Atkins 2018-12-11 15:33:14 -08:00
parent 1681396757
commit 17ab3729e7
2 changed files with 8 additions and 2 deletions

View File

@ -727,8 +727,8 @@ func (e *ObjectConsExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics
Severity: hcl.DiagError,
Summary: "Incorrect key type",
Detail: fmt.Sprintf("Can't use this value as a key: %s.", err.Error()),
Subject: item.ValueExpr.Range().Ptr(),
Expression: item.ValueExpr,
Subject: item.KeyExpr.Range().Ptr(),
Expression: item.KeyExpr,
EvalContext: ctx,
})
known = false

View File

@ -403,6 +403,12 @@ upper(
}),
0,
},
{
`{[]: "yes"}`,
nil,
cty.DynamicVal,
1, // Incorrect key type; Can't use this value as a key: string required
},
{
`{"hello" = "world", "goodbye" = "cruel world"}`,
nil,