mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
+1
-1
@@ -959,7 +959,7 @@ func (v *checker) checkArguments(name string, fn reflect.Type, method bool, argu
|
||||
in = fn.In(i + fnInOffset)
|
||||
}
|
||||
|
||||
if isFloat(in) {
|
||||
if isFloat(in) && isInteger(t) {
|
||||
traverseAndReplaceIntegerNodesWithFloatNodes(&arguments[i], in)
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -2112,3 +2112,57 @@ func TestIssue462(t *testing.T) {
|
||||
_, err := expr.Compile(`$env.unknown(int())`, expr.Env(env))
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestIssue(t *testing.T) {
|
||||
testCases := []struct {
|
||||
code string
|
||||
fail bool
|
||||
}{
|
||||
{
|
||||
code: `func("invalid")`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
code: `func(true)`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
code: `func([])`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
code: `func({})`,
|
||||
fail: true,
|
||||
},
|
||||
{
|
||||
code: `func(1)`,
|
||||
fail: false,
|
||||
},
|
||||
{
|
||||
code: `func(1.5)`,
|
||||
fail: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
ltc := tc
|
||||
t.Run(ltc.code, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
function := expr.Function("func", func(params ...any) (any, error) {
|
||||
return true, nil
|
||||
}, new(func(float64) bool))
|
||||
_, err := expr.Compile(ltc.code, function)
|
||||
if ltc.fail {
|
||||
if err == nil {
|
||||
t.Error("expected an error, but it was nil")
|
||||
t.FailNow()
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("expected nil, but it was %v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6680,7 +6680,6 @@ half(f32 ** f32)
|
||||
half(f32 ** f64)
|
||||
half(f32 + 0.5)
|
||||
half(f32 + 1)
|
||||
half(f32 + f32)
|
||||
half(f32 + f64)
|
||||
half(f32 + i)
|
||||
half(f32 + i32)
|
||||
@@ -12213,7 +12212,6 @@ ok ? score : foo.String
|
||||
ok ? score : foo?.String
|
||||
ok ? score : greet
|
||||
ok ? score : half
|
||||
ok ? score : half("bar")
|
||||
ok ? score : i
|
||||
ok ? score : i32
|
||||
ok ? score : list
|
||||
|
||||
Binary file not shown.
Vendored
-2
@@ -6680,7 +6680,6 @@ half(f32 ** f32)
|
||||
half(f32 ** f64)
|
||||
half(f32 + 0.5)
|
||||
half(f32 + 1)
|
||||
half(f32 + f32)
|
||||
half(f32 + f64)
|
||||
half(f32 + i)
|
||||
half(f32 + i32)
|
||||
@@ -12213,7 +12212,6 @@ ok ? score : foo.String
|
||||
ok ? score : foo?.String
|
||||
ok ? score : greet
|
||||
ok ? score : half
|
||||
ok ? score : half("bar")
|
||||
ok ? score : i
|
||||
ok ? score : i32
|
||||
ok ? score : list
|
||||
|
||||
Reference in New Issue
Block a user