feature (is_nil): support checking func for nil (#3142)

This commit is contained in:
Jim authored and GitHub committed 2023-04-03 14:20:07 -04:00
1 parent 5b26634b8a
commit 60723c070c
2 files changed
+4 -1

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ func IsNil(i any) bool {
return true
}
switch reflect.TypeOf(i).Kind() {
case reflect.Ptr, reflect.Map, reflect.Chan, reflect.Slice:
case reflect.Ptr, reflect.Map, reflect.Chan, reflect.Slice, reflect.Func:
return reflect.ValueOf(i).IsNil()
}
return false
+3
View File
@@ -19,6 +19,7 @@ func Test_IsNil(t *testing.T) {
var testArrayNilPtr *[1]string
var testChanNilPtr *chan string
var testSliceNilPtr *[]string
var testFuncNil func()
var testChanString chan string
@@ -35,6 +36,7 @@ func Test_IsNil(t *testing.T) {
{i: &testChanString, want: false},
{i: "string", want: false},
{i: []string{}, want: false},
{i: func() {}, want: false},
{i: nil, want: true},
{i: testErrNilPtr, want: true},
{i: testMapNilPtr, want: true},
@@ -42,6 +44,7 @@ func Test_IsNil(t *testing.T) {
{i: testChanNilPtr, want: true},
{i: testChanString, want: true},
{i: testSliceNilPtr, want: true},
{i: testFuncNil, want: true},
}
for i, tc := range tc {