From fb9a6cee11c310481cd80f7f6a463d0e5896e9c4 Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Wed, 24 Jan 2024 08:43:07 -0800 Subject: [PATCH] Minor adjustment to inlining to fix a bad bind (#888) --- cel/inlining.go | 3 +-- cel/inlining_test.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cel/inlining.go b/cel/inlining.go index 8c8335d3..e3383b68 100644 --- a/cel/inlining.go +++ b/cel/inlining.go @@ -201,8 +201,7 @@ func (opt *inliningOptimizer) rewritePresenceExpr(ctx *OptimizerContext, prev, i // in most cases. func isBindable(matches []ast.NavigableExpr, inlined ast.Expr, inlinedType *Type) bool { if inlinedType.IsAssignableType(NullType) || - inlinedType.HasTrait(traits.SizerType) || - inlinedType.HasTrait(traits.FieldTesterType) { + inlinedType.HasTrait(traits.SizerType) { return true } for _, m := range matches { diff --git a/cel/inlining_test.go b/cel/inlining_test.go index bdbea553..856eaafc 100644 --- a/cel/inlining_test.go +++ b/cel/inlining_test.go @@ -666,6 +666,29 @@ func TestInliningOptimizerMultiStage(t *testing.T) { inlined: "cel.bind(listA, [1, 1], cel.bind(listB, [1, 1, 1], listB.all(b, b == listA[0]) &&\nlistA.all(a, a == listB[0])) || listA.size() == 0) || false", folded: `true`, }, + { + expr: `has(m.child) && has(m.child.payload)`, + vars: []varDecl{ + { + name: "m", + t: cel.ObjectType("google.expr.proto3.test.NestedTestAllTypes"), + }, + { + name: "m_view", + t: cel.MapType(cel.StringType, cel.ObjectType("google.expr.proto3.test.NestedTestAllTypes")), + }, + }, + inlineVars: []inlineVarExpr{ + { + name: "m.child", + t: cel.ObjectType("google.expr.proto3.test.NestedTestAllTypes"), + alias: "child", + expr: "m_view.nested.child", + }, + }, + inlined: "has(m_view.nested.child) && has(m_view.nested.child.payload)", + folded: "has(m_view.nested.child) && has(m_view.nested.child.payload)", + }, } for _, tst := range tests { tc := tst