diff --git a/lang/ast/structs.go b/lang/ast/structs.go index 0d6906bf..b9887374 100644 --- a/lang/ast/structs.go +++ b/lang/ast/structs.go @@ -3125,15 +3125,7 @@ func (obj *StmtProg) Ordering(produces map[string]interfaces.Node) (*pgraph.Grap } } - // TODO: move to a util package? - cp := func(in map[string]interfaces.Node) map[string]interfaces.Node { - out := make(map[string]interfaces.Node) - for k, v := range in { - out[k] = v // copy the map, not the Node's - } - return out - } - newProduces := cp(produces) // don't modify the input map! + newProduces := CopyNodeMapping(produces) // don't modify the input map! // Overwrite anything in this scope with the shadowed parent variable! for key, val := range prod { diff --git a/lang/ast/util.go b/lang/ast/util.go index 5cc9ce99..6cea932e 100644 --- a/lang/ast/util.go +++ b/lang/ast/util.go @@ -265,3 +265,12 @@ func CollectFiles(ast interfaces.Stmt) ([]string, error) { } return fileList, nil } + +// CopyNodeMapping copies the map of string to node and is used in Ordering. +func CopyNodeMapping(in map[string]interfaces.Node) map[string]interfaces.Node { + out := make(map[string]interfaces.Node) + for k, v := range in { + out[k] = v // copy the map, not the Node's + } + return out +}