From 67da21c7abdef3adf8fcab5674ef1190c1fd49e8 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Fri, 12 Jul 2019 17:27:43 -0700 Subject: [PATCH] reflect/protodesc: only check enum dependency syntax if resolved For proto3 messages with an enum field that could not be resolved, do not check the syntax of that enum dependency. Change-Id: I7c646539351edc35243ab950d335f4018cc4c0e9 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/186001 Reviewed-by: Damien Neil --- reflect/protodesc/desc_validate.go | 2 +- reflect/protodesc/file_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/reflect/protodesc/desc_validate.go b/reflect/protodesc/desc_validate.go index 9a7fbac2..c71ad7bf 100644 --- a/reflect/protodesc/desc_validate.go +++ b/reflect/protodesc/desc_validate.go @@ -159,7 +159,7 @@ func validateMessageDeclarations(ms []filedesc.Message, mds []*descriptorpb.Desc if f.Cardinality() == protoreflect.Required { return errors.New("message field %q using proto3 semantics cannot be required", f.FullName()) } - if f.Enum() != nil && f.Enum().Syntax() != protoreflect.Proto3 { + if f.Enum() != nil && !f.Enum().IsPlaceholder() && f.Enum().Syntax() != protoreflect.Proto3 { return errors.New("message field %q using proto3 semantics may only depend on a proto3 enum", f.FullName()) } } diff --git a/reflect/protodesc/file_test.go b/reflect/protodesc/file_test.go index 9de1d03b..f3e0b0aa 100644 --- a/reflect/protodesc/file_test.go +++ b/reflect/protodesc/file_test.go @@ -831,6 +831,20 @@ func TestNewFile(t *testing.T) { ] }]}] `), + }, { + label: "proto3 message with unresolved enum", + inDesc: mustParseFile(` + name: "test.proto" + package: "" + syntax: "proto3" + message_type: [{ + name: "M" + field: [ + {name:"enum" number:1 label:LABEL_OPTIONAL type:TYPE_ENUM type_name:".fizz.buzz.Enum"} + ] + }] + `), + inOpts: []option{allowUnresolvable()}, // TODO: Test field and oneof handling in validateMessageDeclarations // TODO: Test unmarshalDefault // TODO: Test validateExtensionDeclarations