From 9acc22213e5fbec050904b9886c6df042188cad5 Mon Sep 17 00:00:00 2001 From: sunpeng Date: Tue, 20 Dec 2022 17:39:16 +0800 Subject: [PATCH] fix: fix bug for check unsafe.Pointer isNil (#1319) --- assert/assertions.go | 2 +- assert/assertions_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/assert/assertions.go b/assert/assertions.go index fa1245b18..361d0bdad 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -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() { diff --git a/assert/assertions_test.go b/assert/assertions_test.go index bdab184c1..b5193a582 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -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") + } +}