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

@meta-cla meta-cla Bot added the CLA Signed label Apr 28, 2026
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>
@mszabo-wikia mszabo-wikia force-pushed the fix-autocomplete-before-backslash-qualified-name branch from a06f5d0 to d8ff161 Compare June 5, 2026 16:58
@meta-codesync

meta-codesync Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D107673032. (Because this pull request was imported automatically, there will not be any future comments.)

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