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

protoc: inconsistent source locations emitted for options #6392

Closed
jhump opened this issue Jul 17, 2019 · 2 comments
Closed

protoc: inconsistent source locations emitted for options #6392

jhump opened this issue Jul 17, 2019 · 2 comments
Assignees

Comments

@jhump
Copy link
Contributor

jhump commented Jul 17, 2019

What version of protobuf and what language are you using?
Version: 3.5.1
Language: N/A (descriptor output of protoc)

What operating system (Linux, Windows, ...) and version?
Linux and OS X

What runtime / compiler are you using (e.g., python version or gcc version)
N/A

What did you do?
Compiled the following to a descriptor w/ source info:

// p.proto
option go_package = "foo";

message M {
  repeated int32 f = 1 [packed = true];
}

Command:

protoc --include_source_info p.proto -o p.protoset

What did you expect to see/What did you see instead?

The source locations in the resulting descriptor include a path indicating the file's options field: [8]. This is in addition to the path for the actual specific option: [8,11]. This makes sense per the doc on the SourceCodeInfo.location field in descriptor.proto: https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto#L759

However, the field option is given no such treatment. It does not include a path for the field's options field, which would be [4,0,2,0,8]. It does of course include the path to the specific option: [4,0,2,0,8,2]. This is surprising, not only based on the doc comment linked above, but also because it is inconsistent with the treatment of file options.

(Note that v3.5.1 actually shows all options as uninterpreted options in source info, but I know that is already fixed in newer versions by #4342.)

@acozzette
Copy link
Member

@jhump Thanks for the bug report. Feel free to send me a pull request if you have a fix.

@jhump
Copy link
Contributor Author

jhump commented Jul 19, 2019

I think I may have been wrong on this one. I think I misinterpreted some output I was looking at.

It looks like protoc intentionally does not emit separate locations for each field option, all with a path that references the options field. It instead emits only one for that path, and its span corresponds to all options, from [ to ]. So I was expecting it to look like file options, but it doesn't because fields use a compact syntax for defining options.

I'll test a little more and make sure the output makes sense. I'd expect it to have this behavior for enum value and extension range options, too. Whereas all other options (file, message, enum, one of, and service) can be spread around, so should be treated like file options.

@jhump jhump closed this as completed Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants