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 <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Andrew Bonventre 2018-12-23 16:48:38 -05:00
parent 97d5cb24b1
commit 3b66c00857
2 changed files with 2 additions and 1 deletions

View file

@ -1009,6 +1009,7 @@ func TestIsNil(t *testing.T) {
struct{ x func() bool }{},
struct{ x chan int }{},
struct{ x []string }{},
struct{ x unsafe.Pointer }{},
}
for _, ts := range doNil {
ty := TypeOf(ts).Field(0).Type

View file

@ -1031,7 +1031,7 @@ func (v Value) InterfaceData() [2]uintptr {
func (v Value) IsNil() bool {
k := v.kind()
switch k {
case Chan, Func, Map, Ptr:
case Chan, Func, Map, Ptr, UnsafePointer:
if v.flag&flagMethod != 0 {
return false
}