Skip to content

Commit

Permalink
Minor adjustment to inlining to fix a bad bind (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Jan 24, 2024
1 parent a53bdc9 commit fb9a6ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cel/inlining.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 23 additions & 0 deletions cel/inlining_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fb9a6ce

Please sign in to comment.