proto3-suite
proto3-suite copied to clipboard
Resolution of imported names
Name resolution in compile-proto-file
deviates from that of protoc
and from this portion of the specification:
https://developers.google.com/protocol-buffers/docs/proto3#packages_and_name_resolution
Specifically, compile-proto-file
allows unqualified lookup of imported names, which seems to be nonstandard, but fails to find qualified names unless they start at the top package component. It should look up both qualified and unqualified names relative to the current package, its parent package, and so forth, on up to the root--except for names that start with a period, which are always relative to the root (that is, absolute).
Consider the following two test inputs:
$ cat test1.proto
syntax = "proto3";
package test.sub1;
message Message1 {}
$ cat test2.proto
syntax = "proto3";
package test.sub2;
import "test1.proto";
message Message2 { sub1.Message1 sub = 1; }
protoc
accepts test2.proto
, but rejects it if we remove the sub1.
qualification from the reference to Message1
.
By contrast, compile-proto-file
rejects test2.proto
:
compile-proto-file --proto test2.proto --out t
Error: failed to compile "test2.proto":
NoSuchType (Dots (Path {components = "sub1" :| ["Message1"]}))
But if we remove the sub1
qualification then then compile-proto-file
succeeds--even though protoc
would fail in that case.
If we expand qualification to test.sub1.Message1
or the absolute path .test.sub1.Message1
then both compile-proto-file
and protoc
accept the input.