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:
Martin Atkins 2017-06-16 07:15:14 -07:00
parent 4ab33cdce0
commit 4e18e3a8a8

View File

@ -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 {