Skip to content

Commit 9acc222

Browse files
authored
fix: fix bug for check unsafe.Pointer isNil (#1319)
1 parent 1333b5d commit 9acc222

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

assert/assertions.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ func isNil(object interface{}) bool {
530530
[]reflect.Kind{
531531
reflect.Chan, reflect.Func,
532532
reflect.Interface, reflect.Map,
533-
reflect.Ptr, reflect.Slice},
533+
reflect.Ptr, reflect.Slice, reflect.UnsafePointer},
534534
kind)
535535

536536
if isNilableKind && value.IsNil() {

assert/assertions_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strings"
1616
"testing"
1717
"time"
18+
"unsafe"
1819
)
1920

2021
var (
@@ -2558,3 +2559,10 @@ func TestErrorAs(t *testing.T) {
25582559
})
25592560
}
25602561
}
2562+
2563+
func TestIsNil(t *testing.T) {
2564+
var n unsafe.Pointer = nil
2565+
if !isNil(n) {
2566+
t.Fatal("fail")
2567+
}
2568+
}

0 commit comments

Comments
 (0)