Skip to content

Commit

Permalink
#23 removed automatic nil to string convertion in operators
Browse files Browse the repository at this point in the history
  • Loading branch information
JanErik Keller committed May 3, 2019
1 parent 4f1cfd4 commit 0e8a262
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions gval_evaluationFailure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ func TestModifierTyping(test *testing.T) {
})),
wantErr: "test error",
},
{
name: "eval `nil > 1` returns true #23",
expression: `nil > 1`,
wantErr: "invalid operation (<nil>) > (float64)",
},
}

for i := range evaluationTests {
Expand Down
5 changes: 4 additions & 1 deletion operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ type opFunc func(a, b interface{}) (interface{}, error)
func getStringOpFunc(s func(a, b string) (interface{}, error), f opFunc, typeConversion bool) opFunc {
if typeConversion {
return func(a, b interface{}) (interface{}, error) {
return s(fmt.Sprintf("%v", a), fmt.Sprintf("%v", b))
if a != nil && b != nil {
return s(fmt.Sprintf("%v", a), fmt.Sprintf("%v", b))
}
return f(a, b)
}
}
return func(a, b interface{}) (interface{}, error) {
Expand Down

0 comments on commit 0e8a262

Please sign in to comment.