Return a descriptive error when a map field has a nil element.
I'm not sure if this matches C++, but it makes sense and otherwise
the output is not decodable by this same package. It also parallels
our rejection of nil elements of a repeated field.
diff --git a/proto/encode.go b/proto/encode.go
index d1abc33..b46f760 100644
--- a/proto/encode.go
+++ b/proto/encode.go
@@ -1106,6 +1106,11 @@
for _, key := range keys {
val := v.MapIndex(key)
+ // The only illegal map entry values are nil message pointers.
+ if val.Kind() == reflect.Ptr && val.IsNil() {
+ return errors.New("proto: map has nil element")
+ }
+
keycopy.Set(key)
valcopy.Set(val)