From 7c85df2652bf514a5653d889c13224f756402ca0 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Tue, 9 Jan 2024 14:49:29 +0100 Subject: [PATCH] reflect/protodesc: fix group validation: not supported in proto3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, calling dynamicpb.NewMessage() on a protoreflect.MessageDescriptor that uses Editions would fail with: message field "[…].relatedqueries" is an invalid group: proto: invalid under proto2 semantics (While Go Protobuf does not yet support Editions, C++ programs can save descriptors to a file that is later loaded by a Go program.) Given that groups are only supported in proto2, but not in proto3 (see https://protobuf.dev/editions/features/#message_encoding), I think the conditional meant to say "proto3 semantics". Change-Id: I00368e4433ca60bb883b726e34ee6b8862cfd1e7 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/554955 Reviewed-by: Cassondra Foesch Reviewed-by: Christian Höppner LUCI-TryBot-Result: Go LUCI --- reflect/protodesc/desc_validate.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reflect/protodesc/desc_validate.go b/reflect/protodesc/desc_validate.go index 9af1d564..5f741dfa 100644 --- a/reflect/protodesc/desc_validate.go +++ b/reflect/protodesc/desc_validate.go @@ -314,8 +314,8 @@ func checkValidGroup(fd protoreflect.FieldDescriptor) error { switch { case fd.Kind() != protoreflect.GroupKind: return nil - case fd.Syntax() != protoreflect.Proto2: - return errors.New("invalid under proto2 semantics") + case fd.Syntax() == protoreflect.Proto3: + return errors.New("invalid under proto3 semantics") case md == nil || md.IsPlaceholder(): return errors.New("message must be resolvable") case fd.FullName().Parent() != md.FullName().Parent():