File tree 2 files changed +40
-3
lines changed
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) {
368
368
c .compile (node .Left )
369
369
c .derefInNeeded (node .Left )
370
370
c .compile (node .Right )
371
- c .derefInNeeded (node .Left )
371
+ c .derefInNeeded (node .Right )
372
372
373
373
if l == r && l == reflect .Int && leftAndRightAreSimple {
374
374
c .emit (OpEqualInt )
@@ -382,7 +382,7 @@ func (c *compiler) BinaryNode(node *ast.BinaryNode) {
382
382
c .compile (node .Left )
383
383
c .derefInNeeded (node .Left )
384
384
c .compile (node .Right )
385
- c .derefInNeeded (node .Left )
385
+ c .derefInNeeded (node .Right )
386
386
c .emit (OpEqual )
387
387
c .emit (OpNot )
388
388
Original file line number Diff line number Diff line change 4
4
"context"
5
5
"testing"
6
6
7
- "github.com/expr-lang/expr"
8
7
"github.com/stretchr/testify/require"
8
+
9
+ "github.com/expr-lang/expr"
9
10
)
10
11
11
12
func TestDeref_binary (t * testing.T ) {
@@ -200,3 +201,39 @@ func TestDeref_nil_in_pointer_of_interface(t *testing.T) {
200
201
require .Equal (t , true , output )
201
202
})
202
203
}
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