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

pull/3128/head
Jim 3 years ago committed by GitHub
parent 5b26634b8a
commit 60723c070c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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 {

Loading…
Cancel
Save