Commit 62d3202a authored by Russ Cox's avatar Russ Cox

reflect: fix IsValid vs Kind mismatch after Elem of nil interface

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/151960044
parent 5edff327
......@@ -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)
if x.flag != 0 {
x.flag |= v.flag & flagRO
}
return x
case Ptr:
ptr := v.ptr
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment