1package hclsyntax
2
3import (
4	"github.com/hashicorp/hcl2/hcl"
5)
6
7// setDiagEvalContext is an internal helper that will impose a particular
8// EvalContext on a set of diagnostics in-place, for any diagnostic that
9// does not already have an EvalContext set.
10//
11// We generally expect diagnostics to be immutable, but this is safe to use
12// on any Diagnostics where none of the contained Diagnostic objects have yet
13// been seen by a caller. Its purpose is to apply additional context to a
14// set of diagnostics produced by a "deeper" component as the stack unwinds
15// during expression evaluation.
16func setDiagEvalContext(diags hcl.Diagnostics, expr hcl.Expression, ctx *hcl.EvalContext) {
17	for _, diag := range diags {
18		if diag.Expression == nil {
19			diag.Expression = expr
20			diag.EvalContext = ctx
21		}
22	}
23}
24