Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor adjustment to inlining to fix a bad bind #888

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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