Skip to content

Commit 9a77e2a

Browse files
committed
fix scope handling for control resulting in non-map
1 parent b7af706 commit 9a77e2a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

flow/environment.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ func (e *DefaultEnvironment) FindInScopes(nodescope *Scope, path []string) (yaml
195195
if len(path) > 0 {
196196
scope := nodescope
197197
for scope != nil {
198+
if scope.local == nil {
199+
break
200+
}
198201
val := scope.local[path[0]]
199202
if val != nil {
200203
return yaml.FindR(true, val, e.GetFeatures(), path[1:]...)
@@ -216,8 +219,8 @@ func (e *DefaultEnvironment) FindReference(path []string) (yaml.Node, bool) {
216219
}
217220
return yaml.FindR(true, node(outer.GetRootBinding()), e.GetFeatures(), path[1:]...)
218221
}
219-
//fmt.Printf("FIND %s: %s\n", strings.Join(path,"."), e)
220-
//fmt.Printf("FOUND %s: %v\n", strings.Join(path,"."), keys(nodescope))
222+
// fmt.Printf("FIND %s: %s\n", strings.Join(path,"."), e)
223+
// fmt.Printf("FOUND %s: %v\n", strings.Join(path,"."), keys(nodescope))
221224
if path[0] == yaml.DOCNODE && nodescope != nil {
222225
return e.FindInScopes(nodescope, path[1:])
223226
}
@@ -227,7 +230,7 @@ func (e *DefaultEnvironment) FindReference(path []string) (yaml.Node, bool) {
227230
return nil, false
228231
}
229232

230-
//fmt.Printf("RESOLVE: %s: %s\n",path[0], dynaml.ExpressionType(root.Value()))
233+
// fmt.Printf("RESOLVE: %s: %s\n",path[0], dynaml.ExpressionType(root.Value()))
231234
if len(path) > 1 && path[0] == yaml.SELF {
232235
resolver := root.Resolver()
233236
return resolver.FindReference(path[1:])
@@ -333,11 +336,11 @@ func (e *DefaultEnvironment) Flow(source yaml.Node, shouldOverride bool) (yaml.N
333336

334337
next = Cleanup(next, updateBinding(next, env))
335338
b := reflect.DeepEqual(result, next)
336-
//b,r:=yaml.Equals(result, next,[]string{})
339+
// b,r:=yaml.Equals(result, next,[]string{})
337340
if b {
338341
break
339342
}
340-
//fmt.Printf("****** found diff: %s\n", r)
343+
// fmt.Printf("****** found diff: %s\n", r)
341344
result = next
342345
}
343346
debug.Debug("@@@ Done\n")
@@ -425,8 +428,10 @@ func updateBinding(root yaml.Node, binding dynaml.Binding) CleanupFunction {
425428
ref, ok := yaml.FindR(true, root, binding.GetFeatures(), scope.path...)
426429
if ok {
427430
debug.Debug("found %#v\n", ref.Value())
428-
m := ref.Value().(map[string]yaml.Node)
429-
scope.local = m
431+
scope.local = nil
432+
if m, ok := ref.Value().(map[string]yaml.Node); ok {
433+
scope.local = m
434+
}
430435
}
431436
} else {
432437
break
@@ -459,7 +464,7 @@ func resolveSymbol(env *DefaultEnvironment, name string, scope *Scope) (yaml.Nod
459464
}
460465
for scope != nil {
461466
if nodescope == nil && scope.path != nil && scope.local != nil {
462-
//fmt.Printf("SCOPE NODE: <%s> %v %v\n", strings.Join(scope.path,"."), keys(scope.local), keys(scope.nodescope))
467+
// fmt.Printf("SCOPE NODE: <%s> %v %v\n", strings.Join(scope.path,"."), keys(scope.local), keys(scope.nodescope))
463468
nodescope = scope
464469
}
465470
val := scope.local[name]

0 commit comments

Comments
 (0)