fix: prefer generic call interpretation for f<T>(x) via prec.dynamic#236
Merged
VladimirMakaev merged 1 commit intofwcd:mainfrom Feb 20, 2026
Merged
Conversation
9e43ddb to
2556fe3
Compare
Add _generic_call_expression rule with required type_arguments and prec.dynamic(1) to resolve the <> generic vs comparison ambiguity. When the GLR parser forks on `<` (type_arguments vs comparison operator), the generic call path now has higher dynamic precedence. The rule is aliased to call_expression so the output tree is unchanged. A separate rule is needed because prec.dynamic on the full call_expression (with optional type_arguments) would also boost trailing lambda calls, breaking object literal class_body parsing and getter/setter accessor recognition. Follows the pattern used by tree-sitter-java (prec.dynamic on generic_type) and tree-sitter-go (prec.dynamic on type_arguments).
2556fe3 to
3aec6ae
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_generic_call_expressionrule with requiredtype_argumentsandprec.dynamic(1)to resolve the<>generic-vs-comparison ambiguity<(could betype_argumentsor comparison operator), the generic call path now has higher dynamic precedencecall_expressionso the output tree is unchangedprec.dynamicon the fullcall_expression(with optionaltype_arguments) would also boost trailing lambda calls, breaking object literalclass_bodyparsing and getter/setter accessor recognition (12 test failures)Before
After
Follows the pattern used by tree-sitter-java (
prec.dynamicongeneric_type) and tree-sitter-go (prec.dynamicontype_arguments).Parser size
mainThe
prec.dynamicvariant adds minimal parser states (+0.4%) since the GLR conflict infrastructure already exists.Test plan
f<T>(x)correctly parses as generic callif (x < y)still parses as comparisonnpm run cross-validateshows no regressions