Skip to content

Commit

Permalink
fix: fix bug for check unsafe.Pointer isNil (#1319)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunpe committed Dec 20, 2022
1 parent 1333b5d commit 9acc222
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func isNil(object interface{}) bool {
[]reflect.Kind{
reflect.Chan, reflect.Func,
reflect.Interface, reflect.Map,
reflect.Ptr, reflect.Slice},
reflect.Ptr, reflect.Slice, reflect.UnsafePointer},
kind)

if isNilableKind && value.IsNil() {
Expand Down
8 changes: 8 additions & 0 deletions assert/assertions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"
"testing"
"time"
"unsafe"
)

var (
Expand Down Expand Up @@ -2558,3 +2559,10 @@ func TestErrorAs(t *testing.T) {
})
}
}

func TestIsNil(t *testing.T) {
var n unsafe.Pointer = nil
if !isNil(n) {
t.Fatal("fail")
}
}

0 comments on commit 9acc222

Please sign in to comment.