all: fix reflection behavior for empty lists and maps
The protoreflect documentation states that Get on an empty repeated or
map field returns an invalid (empty, read-only) List or Map. We weren't
doing this; fix it.
The documentation also states that an invalid List or Map may not be
assigned via Set. We were permitting Set with an invalid map; fix this.
Add tests for this behavior in prototest.
Change-Id: I4678af532e192210af0bde7c96a1439a4cd26efa
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/209019
Reviewed-by: Joe Tsai <joetsai@google.com>
diff --git a/internal/impl/convert_map.go b/internal/impl/convert_map.go
index a05b131..34c3fcd 100644
--- a/internal/impl/convert_map.go
+++ b/internal/impl/convert_map.go
@@ -43,7 +43,7 @@
if !ok {
return false
}
- return mapv.v.Type() == c.goType
+ return mapv.v.Type() == c.goType && mapv.IsValid()
}
func (c *mapConverter) IsValidGo(v reflect.Value) bool {