fix: allow a final modifier on a switch pattern's type pattern#230
fix: allow a final modifier on a switch pattern's type pattern#230DragonAxe wants to merge 1 commit into
Conversation
instanceof_expression already accepts optional('final') before its
pattern's type, matching JLS support for `final` on a pattern variable in
both instanceof patterns and switch patterns (JEP 394/405, JEP 441/440).
type_pattern -- the equivalent rule used inside a switch's `case` labels
-- never got the same treatment, so `case final Type x ->` produced an
ERROR node: the parser had no rule for a leading `final` keyword there,
so it consumed `final` itself as if it were the pattern's type name and
the real type as the binding identifier, leaving the actual variable name
as a stray ERROR token.
`case Type x ->` (no modifier) and `instanceof final Type x` both already
parsed correctly; this just brings `case final Type x ->` in line with
them. All existing grammar tests still pass.
|
Disclaimer: This fix was found and documented by Claude while I was working on an auto-formatter for java. I apologize for any inconvenience this might cause. I, the author, am willing to make any adjustments or clarifications if needed. |
|
Hi @DragonAxe, If you encounter any issue switching to our fork as a user or contributor, I would be happy to hear what we could improve to enable that. Since you seem to be using this grammar via the Rust crate, you should hopefully be able to just switch to https://crates.io/crates/tree-sitter-java-orchard. |
instanceof_expression already accepts optional('final') before its pattern's type, matching JLS support for
finalon a pattern variable in both instanceof patterns and switch patterns (JEP 394/405, JEP 441/440). type_pattern -- the equivalent rule used inside a switch'scaselabels -- never got the same treatment, socase final Type x ->produced an ERROR node: the parser had no rule for a leadingfinalkeyword there, so it consumedfinalitself as if it were the pattern's type name and the real type as the binding identifier, leaving the actual variable name as a stray ERROR token.case Type x ->(no modifier) andinstanceof final Type xboth already parsed correctly; this just bringscase final Type x ->in line with them. All existing grammar tests still pass.Fixes #229