Skip to content

Don't join qualified names across newlines in parser#9772

Open
mszabo-wikia wants to merge 1 commit into
facebook:masterfrom
mszabo-wikia:fix-autocomplete-before-backslash-qualified-name
Open

Don't join qualified names across newlines in parser#9772
mszabo-wikia wants to merge 1 commit into
facebook:masterfrom
mszabo-wikia:fix-autocomplete-before-backslash-qualified-name

Conversation

@mszabo-wikia
Copy link
Copy Markdown
Contributor

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:

$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).

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>
@meta-cla meta-cla Bot added the CLA Signed label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant