Repository navigation
fix(cpp): a receiver type written from the global scope is looked up there, and a far lowercase outside type reaches no namesake - #2569
Merged
Conversation
…there, and a far lowercase outside type reaches no namesake The two follow-ups #2567 and #2568 left open. A receiver declared with a leading `::` lost it: the declarator regex started a type at a letter, so `::upb::Arena& a` inside `namespace hpb` was looked up from `hpb` and found a namespace-local `hpb::upb::Arena`. The declared type now keeps a leading `::` where one can stand (not after a name, a template's arguments or a `)`, so `SkipList<Key, Comparator>::Iterator iter` is not read as `::Iterator`), and resolveCppAliasedType no longer takes a function-local `using Foo = Bar;` for `::Foo`. A lowercase outside type declared outside the calling function still used the last-name typed match: #2413's library rule skips such declarations, and #2567's namesake gate took capitalized types only. So a far `absl::flat_hash_set<int> seen` linked `seen.insert(v)` to the project's `util::flat_hash_set::insert`, and a far `std::string text` linked `text.clear()` to a global project `string` class. The gate now covers lowercase types, which are decided as when no class shares their name, and cppFindsOnlyNamesakes reads a `std::` name exactly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
The two C++ receiver follow-ups that #2567 and #2568 left open.
1. A receiver declared with a leading
::lost it. The declarator regex started a type at a letter, so::upb::Arena& awas read asupb::Arena&and looked up from the caller's namespace. Insidenamespace hpb, that found a namespace-localhpb::upb::Arenafirst.::, but only where one can stand: not after a name, a template's arguments or a). A single-character lookbehind does this, soSkipList<Key, Comparator>::Iterator iteris not read as::Iterator.forloops read it the same way.resolveCppAliasedTypeno longer takes a function-localusing Foo = Bar;for::Foo. fix(cpp): an alias of a type written from the global scope names that global type #2568 had dropped that guard because no receiver could reach it. Now one can.2. A lowercase outside type declared outside the calling function still used the last-name typed match. Examples are another function's variable of the same name, or a file's global. #2413's library rule skips such declarations, and #2567's namesake gate covered capitalized types only. So:
absl::flat_hash_set<int> seenlinkedseen.insert(v)to the project'sutil::flat_hash_set::insert;std::string textlinkedtext.clear()to a global projectstringclass.The gate now covers lowercase types too. Their typed match is dropped, and the call is decided as it would be if no class shared the type's name: by the library rule, or by the name strategies for a far declaration.
cppFindsOnlyNamesakesnow reads astd::name exactly, so a globalstringclass is nostd::string.Validation
__tests__/cpp-receiver-global-far-library.test.ts(7 tests): the 5 reproductions fail on main and pass here. The 2 guards pass on both: the project's own lowercase type stays its own, andOuter<T>::Iterator itstays Outer's.::: 3 tests fail;::lookbehind: 1;stdexactness: 1.SkipList<Key, Comparator>::Iterator iterwas read as::Iterator. It also lowered 3 rocksdb confidences. The lookbehind fixed this, and the new guard test pins it.Iterator, so those 109 calls link toleveldb::IteratorandIteratorBaseinstead of the skip list's iterator. This is filed as a follow-up task.🤖 Generated with Claude Code