2018-07-28 20:14:36 +00:00
|
|
|
package hclsyntax
|
|
|
|
|
|
|
|
import (
|
2019-09-09 23:08:19 +00:00
|
|
|
"github.com/hashicorp/hcl/v2"
|
2018-07-28 20:14:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// setDiagEvalContext is an internal helper that will impose a particular
|
|
|
|
// EvalContext on a set of diagnostics in-place, for any diagnostic that
|
|
|
|
// does not already have an EvalContext set.
|
|
|
|
//
|
|
|
|
// We generally expect diagnostics to be immutable, but this is safe to use
|
|
|
|
// on any Diagnostics where none of the contained Diagnostic objects have yet
|
|
|
|
// been seen by a caller. Its purpose is to apply additional context to a
|
|
|
|
// set of diagnostics produced by a "deeper" component as the stack unwinds
|
|
|
|
// during expression evaluation.
|
2018-07-28 20:36:55 +00:00
|
|
|
func setDiagEvalContext(diags hcl.Diagnostics, expr hcl.Expression, ctx *hcl.EvalContext) {
|
2018-07-28 20:14:36 +00:00
|
|
|
for _, diag := range diags {
|
2018-07-28 20:36:55 +00:00
|
|
|
if diag.Expression == nil {
|
|
|
|
diag.Expression = expr
|
2018-07-28 20:14:36 +00:00
|
|
|
diag.EvalContext = ctx
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|