Skip to content

Commit dbbec97

Browse files
committed
Fix checker panic
Fixes #453
1 parent fcf2b55 commit dbbec97

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

checker/checker.go

+5
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,11 @@ func (v *checker) functionReturnType(node *ast.CallNode) (reflect.Type, info) {
560560
fnName = name.Value
561561
}
562562
}
563+
564+
if fn == nil {
565+
return v.error(node, "%v is nil; cannot call nil as function", fnName)
566+
}
567+
563568
switch fn.Kind() {
564569
case reflect.Interface:
565570
return anyType, info{}

expr_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -2014,3 +2014,11 @@ func TestIssue432(t *testing.T) {
20142014
assert.NoError(t, err)
20152015
assert.Equal(t, float64(10), out)
20162016
}
2017+
2018+
func TestIssue453(t *testing.T) {
2019+
env := map[string]any{
2020+
"foo": nil,
2021+
}
2022+
_, err := expr.Compile(`foo()`, expr.Env(env))
2023+
require.Error(t, err)
2024+
}

0 commit comments

Comments
 (0)