mirror of
https://github.com/golang/go
synced 2024-11-23 08:30:05 -07:00
reflect: fix IsValid vs Kind mismatch after Elem of nil interface
LGTM=r R=r CC=golang-codereviews https://golang.org/cl/151960044
This commit is contained in:
parent
5edff32704
commit
62d3202aaa
@ -3939,3 +3939,17 @@ func TestValueString(t *testing.T) {
|
||||
t.Errorf("ValueOf(Impl{}).Method(0).String() = %q, want %q", method.String(), "<func() Value>")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalid(t *testing.T) {
|
||||
// Used to have inconsistency between IsValid() and Kind() != Invalid.
|
||||
type T struct{ v interface{} }
|
||||
|
||||
v := ValueOf(T{}).Field(0)
|
||||
if v.IsValid() != true || v.Kind() != Interface {
|
||||
t.Errorf("field: IsValid=%v, Kind=%v, want true, Interface", v.IsValid(), v.Kind())
|
||||
}
|
||||
v = v.Elem()
|
||||
if v.IsValid() != false || v.Kind() != Invalid {
|
||||
t.Errorf("field elem: IsValid=%v, Kind=%v, want false, Invalid", v.IsValid(), v.Kind())
|
||||
}
|
||||
}
|
||||
|
@ -791,7 +791,9 @@ func (v Value) Elem() Value {
|
||||
})(v.ptr))
|
||||
}
|
||||
x := unpackEface(eface)
|
||||
x.flag |= v.flag & flagRO
|
||||
if x.flag != 0 {
|
||||
x.flag |= v.flag & flagRO
|
||||
}
|
||||
return x
|
||||
case Ptr:
|
||||
ptr := v.ptr
|
||||
|
Loading…
Reference in New Issue
Block a user