Skip to content

Commit 3b66c00

Browse files
committed
reflect: fix panic when Value.IsNil is called for UnsafePointer
UnsafePointer is a valid type kind to call IsNil on. Fixes #29381 Change-Id: Iaf65d582c67f4be52cd1885badf40f174920500b Reviewed-on: https://go-review.googlesource.com/c/155797 Run-TryBot: Andrew Bonventre <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 97d5cb2 commit 3b66c00

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/reflect/all_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ func TestIsNil(t *testing.T) {
10091009
struct{ x func() bool }{},
10101010
struct{ x chan int }{},
10111011
struct{ x []string }{},
1012+
struct{ x unsafe.Pointer }{},
10121013
}
10131014
for _, ts := range doNil {
10141015
ty := TypeOf(ts).Field(0).Type

src/reflect/value.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ func (v Value) InterfaceData() [2]uintptr {
10311031
func (v Value) IsNil() bool {
10321032
k := v.kind()
10331033
switch k {
1034-
case Chan, Func, Map, Ptr:
1034+
case Chan, Func, Map, Ptr, UnsafePointer:
10351035
if v.flag&flagMethod != 0 {
10361036
return false
10371037
}

0 commit comments

Comments
 (0)