fix: fix bug for check unsafe.Pointer isNil (#1319)

pull/1320/head
sunpeng 2022-12-20 17:39:16 +08:00 committed by GitHub
parent 1333b5d3bd
commit 9acc22213e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

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

View File

@ -15,6 +15,7 @@ import (
"strings"
"testing"
"time"
"unsafe"
)
var (
@ -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")
}
}