Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protoparse: doh! we weren't resolving options for oneofs during linking #408

Merged
merged 1 commit into from Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions desc/protoparse/linker.go
Expand Up @@ -372,6 +372,14 @@ func (l *linker) resolveMessageTypes(r *parseResult, fd *dpb.FileDescriptorProto
return err
}
}
for _, ood := range md.OneofDecl {
if ood.Options != nil {
ooName := fmt.Sprintf("%s.%s", fqn, ood.GetName())
if err := l.resolveOptions(r, fd, "oneof", ooName, proto.MessageName(ood.Options), ood.Options.UninterpretedOption, scopes); err != nil {
return err
}
}
}
for _, fld := range md.Extension {
if err := l.resolveFieldTypes(r, fd, prefix, fld, scopes); err != nil {
return err
Expand Down
38 changes: 38 additions & 0 deletions desc/protoparse/linker_test.go
Expand Up @@ -180,6 +180,44 @@ func TestLinkerValidation(t *testing.T) {
},
"foo.proto:1:70: field fu.baz.foobar.a: unknown type baz; resolved to fu.baz which is not defined; consider using a leading dot",
},
{
map[string]string{
"foo.proto": `
syntax = "proto2";
package foo;
import "google/protobuf/descriptor.proto";
extend google.protobuf.FileOptions { optional string fil_foo = 12000; }
extend google.protobuf.MessageOptions { optional string msg_foo = 12000; }
extend google.protobuf.FieldOptions { optional string fld_foo = 12000 [(fld_foo) = "extension"]; }
extend google.protobuf.OneofOptions { optional string oof_foo = 12000; }
extend google.protobuf.EnumOptions { optional string enm_foo = 12000; }
extend google.protobuf.EnumValueOptions { optional string env_foo = 12000; }
extend google.protobuf.ExtensionRangeOptions { optional string ext_foo = 12000; }
extend google.protobuf.ServiceOptions { optional string svc_foo = 12000; }
extend google.protobuf.MethodOptions { optional string mtd_foo = 12000; }
option (fil_foo) = "file";
message Bar {
option (msg_foo) = "message";
oneof foo {
option (oof_foo) = "oneof";
string bar = 1 [(fld_foo) = "field"];
}
extensions 100 to 200 [(ext_foo) = "extensionrange"];
}
enum Baz {
option (enm_foo) = "enum";
ZERO = 0 [(env_foo) = "enumvalue"];
}
service FooService {
option (svc_foo) = "service";
rpc Bar(Bar) returns (Bar) {
option (mtd_foo) = "method";
}
}
`,
},
"", // should success
},
{
map[string]string{
"foo.proto": "package fu.baz; message foobar{ repeated string a = 1 [default = \"abc\"]; }",
Expand Down