Skip to content

Add PHP 8.2 DNF type support ((A&B)|C) - #6

Merged
TomasVotruba merged 1 commit into
mainfrom
add-dnf-types
Oct 5, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
add-dnf-types

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Problem

Disjunctive Normal Form types (PHP 8.2) were not parsed. A parenthesized intersection inside a union, e.g.

public function run((Countable&Traversable)|array $items) {}

failed with unexpected '(', expecting T_VARIABLE.

Change

  • Grammar (internal/php8/php8.y): a parenthesized intersection '(' intersection_type ')' is now accepted as a union member, in the four combinations ((A&B)|C, C|(A&B), (A&B)|(C&D), and appended to a longer union). Adds zero new goyacc conflicts (baseline 3 shift/reduce, 7 reduce/reduce, unchanged).
  • AST (pkg/ast/node.go): Intersection gains OpenParenthesisTkn / CloseParenthesisTkn, set only when the intersection is parenthesized.
  • Printer: emits the parentheses when present, so DNF types round-trip unchanged.
  • Regenerated php8.go via goyacc.
  • Fixed the stale github.com/TomasVotruba/reco imports in php8.y left from the module extraction, so regeneration yields the correct module path.
  • Added internal/php8/dnf_types_test.go (parameter, return, two parenthesized intersections, and print-back-unchanged).

Verification

Full suite and golangci-lint pass. With reco pointed at this branch, a type-coverage scan of symfony/console drops from 3 unparseable files to 1 (the remaining one is an unrelated attribute-position gap).

Parenthesized intersection types are now accepted as union members, e.g.
(Countable&Traversable)|array, in parameter, return and property positions.
The parenthesis tokens are kept on the Intersection node so the type prints
back unchanged.

Also fixes the stale github.com/TomasVotruba/reco imports left in php8.y after
the module extraction, so regeneration produces the correct module path.
@TomasVotruba
TomasVotruba merged commit 4fdb7cc into main Oct 5, 2026
5 checks passed
@TomasVotruba
TomasVotruba deleted the add-dnf-types branch October 5, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant