Don't join qualified names across newlines in parser#9772
Open
mszabo-wikia wants to merge 1 commit into
Open
Conversation
The parser's qualified name scanning would greedily combine a name followed by a backslash into a single qualified name even across line boundaries. This caused `my_func` on one line followed by `\root_ns_func()` on the next to be parsed as a single identifier `my_func\root_ns_func`, which broke autocomplete when the cursor was on a name preceding a root-namespace-qualified call. The fix checks for trailing EndOfLine trivia on the name token before allowing a backslash to continue a qualified name. If the name has a trailing newline, the backslash is treated as the start of a new expression. Human note: while this means the below is no longer valid Hack: ```hack $foo = Bar\ Baz\something(); ``` this doesn't seem to have been intended behavior and autocomplete being broken in positions preceding a `\`-qualified function call is arguably confusing. Such code is also not valid PHP (see https://onlinephp.io?s=RY09CsMwDIXnGHQHETq0V7BbOmTPCbw4rkIMrmX8k6X07rVTSsUD6Qm9T9d73CKIYJ6Uo7GEswJhvckZJ3yBGGJdvLOYiymtrTXY4jjgyny-SFyY_XE2kN0YR2qlw6j6JlGpKWBJlbp_g2gC8Ud0wM7u8QWcGhJvqGfd3STl8UL9Um38AA%2C%2C&v=8.2.20). Co-authored-by: Claude Opus 4.6 <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.
The parser's qualified name scanning would greedily combine a name followed by a backslash into a single qualified name even across line boundaries. This caused
my_funcon one line followed by\root_ns_func()on the next to be parsed as a single identifiermy_func\root_ns_func, which broke autocomplete when the cursor was on a name preceding a root-namespace-qualified call.The fix checks for trailing EndOfLine trivia on the name token before allowing a backslash to continue a qualified name. If the name has a trailing newline, the backslash is treated as the start of a new expression.
Human note: while this means the below is no longer valid Hack:
this doesn't seem to have been intended behavior and autocomplete being broken in positions preceding a
\-qualified function call is arguably confusing.Such code is also not valid PHP (see https://onlinephp.io?s=RY09CsMwDIXnGHQHETq0V7BbOmTPCbw4rkIMrmX8k6X07rVTSsUD6Qm9T9d73CKIYJ6Uo7GEswJhvckZJ3yBGGJdvLOYiymtrTXY4jjgyny-SFyY_XE2kN0YR2qlw6j6JlGpKWBJlbp_g2gC8Ud0wM7u8QWcGhJvqGfd3STl8UL9Um38AA%2C%2C&v=8.2.20).