Skip to content
Open
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
10 changes: 6 additions & 4 deletions optimizer/fold.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,12 @@ func (fold *fold) Visit(node *Node) {
Name: "filter",
Arguments: []Node{
base.Arguments[0],
&BinaryNode{
Operator: "&&",
Left: base.Arguments[1].(*PredicateNode).Node,
Right: n.Arguments[1].(*PredicateNode).Node,
&PredicateNode{
Node: &BinaryNode{
Operator: "&&",
Left: base.Arguments[1].(*PredicateNode).Node,
Right: n.Arguments[1].(*PredicateNode).Node,
},
},
},
})
Expand Down
6 changes: 4 additions & 2 deletions optimizer/fold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ func TestOptimize_constant_folding_filter_filter(t *testing.T) {
Value: 2,
},
},
&ast.BoolNode{
Value: true,
&ast.PredicateNode{
Node: &ast.BoolNode{
Value: true,
},
},
},
Throws: false,
Expand Down
39 changes: 39 additions & 0 deletions test/issues/857/issue_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package main

import (
"testing"

"github.com/expr-lang/expr"
"github.com/expr-lang/expr/internal/testify/require"
)

func TestIssue857(t *testing.T) {
foo := map[string]any{
"entry": map[string]any{
"alpha": "x",
"beta": 1,
},
}
bar := map[string]any{
"entry": map[string]any{
"alpha": "x",
"beta": 1,
},
}

env := map[string]any{
"foo": foo,
"bar": bar,
}

code := `
foo
| keys()
| filter(# in bar)
| filter(foo[#].alpha == bar[#].alpha)
| filter(foo[#].beta == bar[#].beta)
`

_, err := expr.Compile(code, expr.Env(env))
require.NoError(t, err)
}
Loading