Skip to content

Commit

Permalink
Fix checker panic
Browse files Browse the repository at this point in the history
Fixes #453
  • Loading branch information
antonmedv committed Nov 16, 2023
1 parent fcf2b55 commit dbbec97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,11 @@ func (v *checker) functionReturnType(node *ast.CallNode) (reflect.Type, info) {
fnName = name.Value
}
}

if fn == nil {
return v.error(node, "%v is nil; cannot call nil as function", fnName)
}

switch fn.Kind() {
case reflect.Interface:
return anyType, info{}
Expand Down
8 changes: 8 additions & 0 deletions expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2014,3 +2014,11 @@ func TestIssue432(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, float64(10), out)
}

func TestIssue453(t *testing.T) {
env := map[string]any{
"foo": nil,
}
_, err := expr.Compile(`foo()`, expr.Env(env))
require.Error(t, err)
}

0 comments on commit dbbec97

Please sign in to comment.