File tree Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -368,7 +368,7 @@ func (c *compiler) BinaryNode(node *ast.BinaryNode) {
368368 c .compile (node .Left )
369369 c .derefInNeeded (node .Left )
370370 c .compile (node .Right )
371- c .derefInNeeded (node .Left )
371+ c .derefInNeeded (node .Right )
372372
373373 if l == r && l == reflect .Int && leftAndRightAreSimple {
374374 c .emit (OpEqualInt )
@@ -382,7 +382,7 @@ func (c *compiler) BinaryNode(node *ast.BinaryNode) {
382382 c .compile (node .Left )
383383 c .derefInNeeded (node .Left )
384384 c .compile (node .Right )
385- c .derefInNeeded (node .Left )
385+ c .derefInNeeded (node .Right )
386386 c .emit (OpEqual )
387387 c .emit (OpNot )
388388
Original file line number Diff line number Diff line change 44 "context"
55 "testing"
66
7- "github.com/expr-lang/expr"
87 "github.com/stretchr/testify/require"
8+
9+ "github.com/expr-lang/expr"
910)
1011
1112func TestDeref_binary (t * testing.T ) {
@@ -200,3 +201,39 @@ func TestDeref_nil_in_pointer_of_interface(t *testing.T) {
200201 require .Equal (t , true , output )
201202 })
202203}
204+
205+ func TestDeref_сommutative (t * testing.T ) {
206+ a := "ok"
207+ b := "ok"
208+
209+ type Env struct {
210+ A string
211+ B * string
212+ }
213+
214+ env := Env {
215+ A : a ,
216+ B : & b ,
217+ }
218+
219+ tests := []struct {
220+ code string
221+ want bool
222+ }{
223+ {`A == B` , true },
224+ {`B == A` , true },
225+ {`A != B` , false },
226+ {`B != A` , false },
227+ }
228+
229+ for _ , test := range tests {
230+ t .Run (test .code , func (t * testing.T ) {
231+ program , err := expr .Compile (test .code , expr .Env (env ))
232+ require .NoError (t , err )
233+
234+ out , err := expr .Run (program , env )
235+ require .NoError (t , err )
236+ require .Equal (t , test .want , out )
237+ })
238+ }
239+ }
You can’t perform that action at this time.
0 commit comments