fix: span a binary condition's node from its left operand - #2615
Merged
manticore-projects merged 1 commit intoSep 12, 2026
Merged
Conversation
Seven productions take their left operand as a parameter, so the caller has already consumed those tokens when JJTree opens the node and the range starts at the operator. A node for `a IN (1, 2)` covered only `IN (1, 2)`, and one for `a = 1` only `= 1`, leaving anyone reading `jjtGetFirstToken()` a range that excludes the operand the condition is about. Comparisons are a regression from 1b51f05, which moved the left operand out of RegularCondition and into the caller as part of the Pratt refactor. IN, LIKE, SIMILAR TO and IS DISTINCT have taken their operand as a parameter for far longer and were already reporting the narrow range, so before that refactor the two halves of the family disagreed with each other. Link those nodes through an overload that starts the range at the left operand, which fixes the regression and makes the family consistent. testDetectInExpressions asserted the narrow range and now expects the wider one. Between, IsNullExpression, IsBooleanExpression, IsUnknownExpression, MemberOfExpression and OverlapsCondition also take a left operand but build no node at all, so they keep returning null and are left alone here.
Contributor
|
Good job! Thank you for correcting this, appreciated! |
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.
A node built for a binary condition does not cover the operand the condition is about. Nested in an
AND, so that the condition is not also the outermost expression:Seven productions take their left operand as a parameter —
RegularConditionRHS,InExpression,IncludesExpression,ExcludesExpression,LikeExpression,SimilarToExpression,IsDistinctExpression. The caller has consumed those tokens by the time JJTree opens the node, so its range starts at the operator.Which half is a regression
ANDa = 1a = 1= 1a = 1a in (1, 2)in (1, 2)in (1, 2)a in (1, 2)a like 'p'like 'p'like 'p'a like 'p'a similar to 'p'similar to 'p'similar to 'p'a similar to 'p'a is distinct from 1is distinct from 1is distinct from 1a is distinct from 1Only the comparison row is new. 1b51f05 split
RegularCondition()intoRegularConditionRHS(Expression leftExpression, int)for the Pratt rewrite, which moved comparisons onto the same footing as the rest of the family.Worth saying plainly: 5.3 was not consistent here either. Comparisons spanned their operand and the other four did not, so the refactor did not introduce the defect so much as finish spreading it. Fixing only the comparison row would restore 5.3 while leaving
a = 1anda in (1, 2)disagreeing inside a singleWHERE, so this fixes all seven.A condition is only affected while it is not the outermost expression of its clause — at the top of a
WHEREthe surrounding production has already opened the node, and the range comes out right. That is whySELECT * FROM t WHERE a IN (1,2)looks correct and the same condition behind anANDdoes not.The behaviour change
SelectASTTest.testDetectInExpressionspinned the narrow range and moves with this:Column 32 is the
INkeyword, column 30 theait tests. I read the old value as describing what the parser did rather than what it owed the caller, but it is a visible change for anyone readingjjtGetFirstToken()off these nodes, and it is the reason this PR is worth a second look rather than a rubber stamp. Happy to narrow it to the comparison regression alone if you would rather keep the existingINrange.Not addressed
Between,IsNullExpression,IsBooleanExpression,IsUnknownExpression,MemberOfExpressionandOverlapsConditiontake a left operand on the same pattern but never calllinkAST, sogetASTNode()returns null for them in 5.3 and on master alike. Separate gap, left alone.Testing
testBinaryConditionNodeStartsAtItsLeftOperandwalks one nested case per fixed production and asserts each node maps back to its own source text. Full suite: 6607 tests, 0 failures.