Repository navigation
descriptor: resolve a type name without a leading dot against its enclosing scopes - #811
Open
dfedoryshchev wants to merge 1 commit into
Open
dfedoryshchev wants to merge 1 commit into
dfedoryshchev wants to merge 1 commit into
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #635.
#797 targets the same issue. As I noted there, it resolves a dotted name whole at every scope, while protoc resolves only the first component against the scopes; this one follows protoc. If you would rather take #797 with that changed, I am happy to close this.
DescriptorPoolstrips an optional leading dot and looks the rest up as one fully-qualified name, so on a hand-built descriptortype_name: "M"on a field ofa.Holderfails withUnresolvedTypeName, or links to a root-levelMfrom an imported file with no package where protoc and protobuf-go linka.M.I took the first option from the issue: a new
lookup_type_namefollowsLookupSymbolNoPlaceholder. A leading dot means fully qualified; otherwise each scope enclosing the field, extension or method is tried innermost first, then the name as written. A compound nameA.Bstops at the innermost scope that definesA, and a match in a file that is not imported is passed over for one further out, as protoc'sFindSymboldoes.resolve_singularandresolve_message_type_nameboth go through it, sotype_name,extendee,input_typeandoutput_typeall get it.Names with a leading dot, which is everything protoc writes, take the same single map lookup as before. The test that pinned
"Holder"as unresolved now uses names no type has, and the docs onUnresolvedTypeNameandadd_file_descriptor_setsay what the pool does now.One place I went simpler than protoc: the pool has no package symbols, so for a compound name a scope counts as a package if any registered symbol sits under it. A package that declares nothing cannot be the target of a lookup anyway, so I don't think the difference shows, but say if you'd rather I register packages properly.
New tests in
pool_e2e.rscover the issue's case, a nested and a compound name, a dotless full name, method types, the protocBar.Bazexample that must not resolve, a partly qualified name through the package, and the pass-over of a non-imported match. Onmain, three of the four new tests fail; theBar.Bazone passes there too, since it guards against resolving too much. With the fix,cargo test -p buffa-descriptor --features reflect --test pool_e2epasses (168), and rustfmt and clippy are clean on the crate. I have not run the full workspace or conformance locally.