zcl: allow nil Variables in EvalContext
it's acceptable to have "Variables" set to nil in an EvalContext, if a particular scope has no variables at all. If _no_ contexts in the chain have non-nil variables, this is considered to mean that variables are not allowed at all, which produces a different error message.
This commit is contained in:
parent
4ab33cdce0
commit
4e18e3a8a8
@ -68,7 +68,22 @@ func (t Traversal) TraverseAbs(ctx *EvalContext) (cty.Value, Diagnostics) {
|
||||
root := split.Abs[0].(TraverseRoot)
|
||||
name := root.Name
|
||||
|
||||
if ctx == nil || ctx.Variables == nil {
|
||||
thisCtx := ctx
|
||||
hasNonNil := false
|
||||
for thisCtx != nil {
|
||||
if thisCtx.Variables == nil {
|
||||
thisCtx = thisCtx.parent
|
||||
continue
|
||||
}
|
||||
hasNonNil = true
|
||||
val, exists := thisCtx.Variables[name]
|
||||
if exists {
|
||||
return split.Rel.TraverseRel(val)
|
||||
}
|
||||
thisCtx = thisCtx.parent
|
||||
}
|
||||
|
||||
if !hasNonNil {
|
||||
return cty.DynamicVal, Diagnostics{
|
||||
{
|
||||
Severity: DiagError,
|
||||
@ -79,15 +94,6 @@ func (t Traversal) TraverseAbs(ctx *EvalContext) (cty.Value, Diagnostics) {
|
||||
}
|
||||
}
|
||||
|
||||
thisCtx := ctx
|
||||
for thisCtx != nil {
|
||||
val, exists := thisCtx.Variables[name]
|
||||
if exists {
|
||||
return split.Rel.TraverseRel(val)
|
||||
}
|
||||
thisCtx = thisCtx.parent
|
||||
}
|
||||
|
||||
suggestions := make([]string, 0, len(ctx.Variables))
|
||||
thisCtx = ctx
|
||||
for thisCtx != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user