Skip to content

fix: keep parens around intersection types inside unions - #2544

Closed
Dextheking1 wants to merge 4 commits into
prettier:mainfrom
Dextheking1:fix/dnf-types-parens
Closed

Dextheking1 wants to merge 4 commits into
prettier:mainfrom
Dextheking1:fix/dnf-types-parens

Conversation

@Dextheking1

Copy link
Copy Markdown
Contributor

(A&B)|C lost its parens when printed, so the output was A&B|C. That is a parse error in PHP. DNF types need the parens around the intersection part.

Fix is in needs-parens: an intersectiontype inside a uniontype now keeps its parens. A standalone (A&B) still drops them and prints as A&B.

New fixture under tests/dnf-types covers param, return, closure and arrow function types.

Verified with jest: the new fixture passes and the full suite passes (102 suites, 596 tests). AST_COMPARE=1 also passes on the new fixture, so the output parses back.

Fixes #2450

@Dextheking1
Dextheking1 marked this pull request as ready for review October 23, 2026 02:14
@Dextheking1

Copy link
Copy Markdown
Contributor Author

closing this, #2470 already covers it and was first. the tests/dnf-types fixture in here might be useful for it, feel free to take it

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.

Combining intersection and union types leads to syntax error

1 participant