Repository navigation
fix: allow match expressions as cast and clone operands - #309
Conversation
Preserve regression coverage for casts, bare clone, and function-style clone arguments containing match expressions. The general operand fix provides the implementation. Refs tree-sitter#308.
Accept cast keywords as expression names so argument values can continue into scoped calls and compound expressions. Keep class-name aliases limited to cast spellings that PHP permits as class identifiers. Accept type keywords in valid global and class constant declarations, with coverage for reserved names, typed constants, casts, and named arguments. Restore example parsing for the affected WordPress file. Fixes tree-sitter#295.
Use expression operands and PHP precedence instead of operand allowlists so match, yield, nested clones, and exponentiation parse consistently. Allow general instanceof left operands so casts retain their precedence. Remove the cast-variable workaround: casts apply to assignment results, not assignment targets. Align unary and error-suppression precedence with casts and exponentiation. Cover assignments, coalescing, conditionals, includes, print, throw, yields, nested clones, and unary operators with PHP-validated cases. Fixes tree-sitter#308.
93609cb to
63f4ceb
Compare
PHPUnit added a name-resolution fixture containing an intentionally invalid assignment. Expect its parse failure so example checks reject real regressions without failing on this upstream negative test.
Regenerate both PHP parsers with tree-sitter 0.27.2 for keyword identifiers and general cast and clone operands with PHP operator precedence.
Prepare the keyword identifier and constant parsing fixes for release. Keep package manifests, lockfiles, and parser metadata in sync.
63f4ceb to
6ecd578
Compare
|
Thanks, @akashchamp, for identifying this and contributing the fix and regression test! Your report led us to look more closely at how we handle cast and clone operands. We kept the match regression tests, but replaced the two explicit The merged implementation uses general expression operands with explicit precedence. We also removed the cast-variable workaround, corrected casts around assignment results, and aligned the related Your original contribution is preserved as a test-only commit with your author credit. We added coverage for function-style This PR also incorporated the keyword identifier/constant fixes from #307. Generated parser updates remain in one separate commit, followed by the version bump. The example-parsing CI failure turned out to be a newly added, intentionally invalid PHPUnit fixture, which we added to the expected-invalid list. Thanks again for getting this started! |
(int)match($x) { ... }andclone match($x) { ... }are valid PHP but parsed as errors, becausecast_expressionandclone_expressiondid not accept amatch_expressionoperand. This adds it to both.Fixes #308. I left
(int)yield(also listed there) out, since it is a separate construct.Checked with
tree-sitter test(149/149 parses pass) andnpm run lint. The new corpus test fails on the old parser and passes on the new one. Parser files are rebuilt by tree-sitter 0.27.1 in a separatechore: generatecommit.