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