hcl/hclsyntax: Don't eat errors in IndexExpr collection or key
Due to incorrect diagnostics discipline here, the result of the index operation was overwriting any diagnostics from either the collection or the key expressions.
This commit is contained in:
parent
854da97291
commit
a085fdcd82
@ -604,8 +604,9 @@ func (e *IndexExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
|
||||
diags = append(diags, collDiags...)
|
||||
diags = append(diags, keyDiags...)
|
||||
|
||||
val, diags := hcl.Index(coll, key, &e.SrcRange)
|
||||
setDiagEvalContext(diags, e, ctx)
|
||||
val, indexDiags := hcl.Index(coll, key, &e.SrcRange)
|
||||
setDiagEvalContext(indexDiags, e, ctx)
|
||||
diags = append(diags, indexDiags...)
|
||||
return val, diags
|
||||
}
|
||||
|
||||
|
@ -981,6 +981,16 @@ upper(
|
||||
cty.StringVal("hello"),
|
||||
0,
|
||||
},
|
||||
{
|
||||
`["boop"].foo[index]`, // index is a variable to force IndexExpr instead of traversal
|
||||
&hcl.EvalContext{
|
||||
Variables: map[string]cty.Value{
|
||||
"index": cty.NumberIntVal(0),
|
||||
},
|
||||
},
|
||||
cty.DynamicVal,
|
||||
1, // expression ["boop"] does not have attributes
|
||||
},
|
||||
|
||||
{
|
||||
`foo`,
|
||||
|
Loading…
Reference in New Issue
Block a user