From 0991264c8cd2fed3fad2a41a44255a8090521788 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Wed, 22 May 2019 13:15:51 -0400 Subject: [PATCH] lang: funcs: Use the correct arg names when running a pure func We were using the default argnames when the actual list of names was available. Use these instead, and validate that we have the correct number of them. --- lang/funcs/funcs.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lang/funcs/funcs.go b/lang/funcs/funcs.go index 1841085a..9a76ee5a 100644 --- a/lang/funcs/funcs.go +++ b/lang/funcs/funcs.go @@ -25,7 +25,6 @@ import ( "github.com/purpleidea/mgmt/lang/interfaces" "github.com/purpleidea/mgmt/lang/types" - "github.com/purpleidea/mgmt/util" "github.com/purpleidea/mgmt/util/errwrap" ) @@ -160,6 +159,11 @@ func PureFuncExec(handle interfaces.Func, args []types.Value) (types.Value, erro return nil, fmt.Errorf("must be kind func") } + ord := handle.Info().Sig.Ord + if i, j := len(ord), len(args); i != j { + return nil, fmt.Errorf("expected %d args, got %d", i, j) + } + wg := &sync.WaitGroup{} defer wg.Wait() @@ -233,7 +237,7 @@ func PureFuncExec(handle interfaces.Func, args []types.Value) (types.Value, erro st := types.NewStruct(si) for i, arg := range args { - name := util.NumToAlpha(i) // assume (incorrectly) for now... + name := handle.Info().Sig.Ord[i] if err := st.Set(name, arg); err != nil { // populate struct select { case errch <- errwrap.Wrapf(err, "struct set failure"):