Skip to content

fix: keep parens around match when it is called or dereferenced - #2552

Open
maoxor wants to merge 1 commit into
prettier:mainfrom
maoxor:fix-match-dereference-parens
Open

maoxor wants to merge 1 commit into
prettier:mainfrom
maoxor:fix-match-dereference-parens

Conversation

@maoxor

@maoxor maoxor commented Oct 29, 2026

Copy link
Copy Markdown

PHP doesn't allow calling, indexing or accessing a member of a bare match expression, but the parentheses around it were dropped. Laravel's CloudBootstrapper has

return (match (true) {
    // ...
    default => fn () => true,
})();

which became match (true) { ... }();, a syntax error. The same happens with [0], ->prop, ?->prop, ->method(), ::CONST, ::$prop and ::method().

match now gets the same rule as yield in needs-parens.mjs: parentheses when it is the what of a call or lookup. The new tests/match/dereference.php covers each case, plus match (...) {...} + 1, which still doesn't need any. yarn test (including the standalone build), AST_COMPARE=1 yarn test:node and yarn lint pass, and CloudBootstrapper.php formats to valid PHP again.

PHP does not allow calling, indexing or accessing a member of a bare `match` expression, so `(match (...) {...})()` must keep its parentheses.
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.

1 participant