internal/impl: fix aberrant message detection logic

In very old messages predating the existence of the size cache or the
proto3 unknown fields, it is possible that the generated struct lacks both
XXX_ fields and ones tagged with "protobuf". This can happen with a message
that only contains oneofs. As such, check for the "protobuf_oneof" tag as well.

Change-Id: I1981cd7dde68aece1a013356b6bc91cc5529f951
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/210747
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2019-12-10 17:28:03 -08:00 committed by Damien Neil
parent 8517608739
commit d65001875f

View File

@ -115,7 +115,7 @@ func legacyLoadMessageDesc(t reflect.Type, name pref.FullName) pref.MessageDescr
hasProtoField := false
for i := 0; i < nfield; i++ {
f := t.Elem().Field(i)
if tag := f.Tag.Get("protobuf"); tag != "" || strings.HasPrefix(f.Name, "XXX_") {
if f.Tag.Get("protobuf") != "" || f.Tag.Get("protobuf_oneof") != "" || strings.HasPrefix(f.Name, "XXX_") {
hasProtoField = true
break
}