From 1515728494018d000aada9fda87d26642ac392b1 Mon Sep 17 00:00:00 2001 From: TristonianJones Date: Fri, 18 Aug 2023 19:53:57 -0700 Subject: [PATCH] Ensure stable ordering of overload candidates during dynamic dispatch --- cel/cel_test.go | 3 ++- common/decls/decls.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cel/cel_test.go b/cel/cel_test.go index b7dd7996..0f8e36a1 100644 --- a/cel/cel_test.go +++ b/cel/cel_test.go @@ -2081,7 +2081,8 @@ func TestDynamicDispatch(t *testing.T) { ), ) out, err := interpret(t, env, ` - [1, 2].first() == 1 + dyn([]).first() == 0 + && [1, 2].first() == 1 && [1.0, 2.0].first() == 1.0 && ["hello", "world"].first() == "hello" && [["hello"], ["world", "!"]].first().first() == "hello" diff --git a/common/decls/decls.go b/common/decls/decls.go index 0284f8db..734ebe57 100644 --- a/common/decls/decls.go +++ b/common/decls/decls.go @@ -243,7 +243,8 @@ func (f *FunctionDecl) Bindings() ([]*functions.Overload, error) { // performs dynamic dispatch to the proper overload based on the argument types. bindings := append([]*functions.Overload{}, overloads...) funcDispatch := func(args ...ref.Val) ref.Val { - for _, o := range f.overloads { + for _, oID := range f.overloadOrdinals { + o := f.overloads[oID] // During dynamic dispatch over multiple functions, signature agreement checks // are preserved in order to assist with the function resolution step. switch len(args) {