Skip to content

fix(php): stop group-form use function/const from claiming class names (#26) - #30

Merged
filipechagas merged 1 commit into
v8from
fix/php-group-use-kind-26
Aug 5, 2026
Merged

fix(php): stop group-form use function/const from claiming class names (#26)#30
filipechagas merged 1 commit into
v8from
fix/php-group-use-kind-26

Conversation

@filipechagas

Copy link
Copy Markdown
Collaborator

Fixes #26 (discovered during #19; sequenced before #21 so a wrongly claimed short name can't become a wrongly decisive refusal).

What

Group-form use function A\{f, g}; and use const A\{K}; put the keyword on the declaration node, not the clause, so those names wrongly entered _resolve_php_type_references's class-name map (pre-existing at 102ae79). The shared parser #19 landed already computed the correct kind behind an apply_declaration_kind=False compatibility flag; this removes the flag and its call site, leaving one code path that always honors the declaration-level keyword. Strictly subtractive.

Test evidence

  • Red first: 3 of 4 new tests failed against unfixed code, matching the issue's stated wrong output; the over-subtraction guard (use App\Cms\{Page}; still claims the class name, decoy gets no edge) passed on both sides by design.
  • Green: 114 across the PHP suites; full suite 4061 passed / 36 skipped / 0 failed (baseline 4057/36 + 4).
  • Independently reproduced by the orchestrator: 4061/36.
  • grep -rn apply_declaration_kind across the repo returns nothing.

Note for #21/#22

After this fix a group-imported function/const short name reaches the repoint loop's namespace-relative arm and ends as a bare stub — so it arrives at the future PhpNameResolver with no class claim. _php_use_clause_context and _php_use_declaration_facts now agree on use_kind for every spelling.

🤖 Generated with Claude Code

…ass names (#26)

`_resolve_php_type_references` builds its per-file class-name map from `use`
statements and correctly refuses `use function` / `use const` — but only
when the keyword sits on the CLAUSE. tree-sitter-php (0.24.1) puts it on the
DECLARATION for the group form, and the pass only ever iterated clause
children, so `use function Vendor\Sdk\{Render};` registered `Render` as a
claimed class name. Any `inherits` / `implements` / `mixes_in` / `imports` /
`references` to that short name in the same file was then treated as an
explicit import and re-pointed onto an FQN-labeled external stub — a stub
naming a function or a constant, not a class.

#19 already extracted the parser into `_php_use_declaration_facts`, which
reads the declaration-level keyword and reports the right `use_kind`; the
`imports`-edge capture consumes it that way today. This pass was the only
caller passing `apply_declaration_kind=False`, purely to keep #19's
metadata-only constraint byte-exact. Drop the argument and delete the flag,
so one code path serves both consumers and cannot drift again.

Strictly subtractive: it can only remove a class-name claim, which makes the
affected reference fall back to the namespace-relative FQN or to the legacy
unique-label rewire — the same place the unbraced spelling has always left
it. Worth landing before #21's decisive-refusal work, where a wrongly
claimed short name would become a wrongly decisive refusal. Pre-existing
defect, not a regression from #19.

Tests go through the public `extract()` seam with the plain form as the
side-by-side control in the same test: group-vs-plain for `use function` and
for `use const` (both spellings must land on the same bare stub, and no
`Vendor\Sdk\*` class stub may be minted), every member of a multi-member
group rejected, and an over-subtraction guard — a keyword-less group
`use App\Cms\{Page};` still claims its member and resolves past a decoy
`App\Models\Page`, which gets no edge. 3 of the 4 were red before this
change; the guard was green both sides.

Suite: 4061 passed / 36 skipped (baseline 4057 / 36 plus 4 new).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP: group-form use function / use const leaks into the class-name map

1 participant