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:
parent
1681396757
commit
17ab3729e7
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user