diff --git a/checker/checker.go b/checker/checker.go index 8e536518c..0d10e0bf3 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -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 } diff --git a/expr_test.go b/expr_test.go index 903336d10..638ae3b84 100644 --- a/expr_test.go +++ b/expr_test.go @@ -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() + } + } + }) + } +} diff --git a/test/fuzz/fuzz_corpus.txt b/test/fuzz/fuzz_corpus.txt index 3d3491ad4..2bb8ab7fb 100644 --- a/test/fuzz/fuzz_corpus.txt +++ b/test/fuzz/fuzz_corpus.txt @@ -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 diff --git a/test/fuzz/fuzz_expr_seed_corpus.zip b/test/fuzz/fuzz_expr_seed_corpus.zip index aef08934d..0fd46ab3a 100644 Binary files a/test/fuzz/fuzz_expr_seed_corpus.zip and b/test/fuzz/fuzz_expr_seed_corpus.zip differ diff --git a/testdata/examples.txt b/testdata/examples.txt index 3d3491ad4..2bb8ab7fb 100644 --- a/testdata/examples.txt +++ b/testdata/examples.txt @@ -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