Skip to content

Commit fb9a6ce

Browse files
Minor adjustment to inlining to fix a bad bind (#888)
1 parent a53bdc9 commit fb9a6ce

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

cel/inlining.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ func (opt *inliningOptimizer) rewritePresenceExpr(ctx *OptimizerContext, prev, i
201201
// in most cases.
202202
func isBindable(matches []ast.NavigableExpr, inlined ast.Expr, inlinedType *Type) bool {
203203
if inlinedType.IsAssignableType(NullType) ||
204-
inlinedType.HasTrait(traits.SizerType) ||
205-
inlinedType.HasTrait(traits.FieldTesterType) {
204+
inlinedType.HasTrait(traits.SizerType) {
206205
return true
207206
}
208207
for _, m := range matches {

cel/inlining_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,29 @@ func TestInliningOptimizerMultiStage(t *testing.T) {
666666
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",
667667
folded: `true`,
668668
},
669+
{
670+
expr: `has(m.child) && has(m.child.payload)`,
671+
vars: []varDecl{
672+
{
673+
name: "m",
674+
t: cel.ObjectType("google.expr.proto3.test.NestedTestAllTypes"),
675+
},
676+
{
677+
name: "m_view",
678+
t: cel.MapType(cel.StringType, cel.ObjectType("google.expr.proto3.test.NestedTestAllTypes")),
679+
},
680+
},
681+
inlineVars: []inlineVarExpr{
682+
{
683+
name: "m.child",
684+
t: cel.ObjectType("google.expr.proto3.test.NestedTestAllTypes"),
685+
alias: "child",
686+
expr: "m_view.nested.child",
687+
},
688+
},
689+
inlined: "has(m_view.nested.child) && has(m_view.nested.child.payload)",
690+
folded: "has(m_view.nested.child) && has(m_view.nested.child.payload)",
691+
},
669692
}
670693
for _, tst := range tests {
671694
tc := tst

0 commit comments

Comments
 (0)