reflect: fix IsValid vs Kind mismatch after Elem of nil interface
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/151960044
diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go
index b72c4b1..d17ef5c 100644
--- a/src/reflect/all_test.go
+++ b/src/reflect/all_test.go
@@ -3939,3 +3939,17 @@
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())
+ }
+}