Skip to content

Fix signed number after ')' or ']' being lexed as a literal - #287

Merged
git-hulk merged 1 commit into
AfterShip:masterfrom
therealpandey:fix/signed-number-after-bracket
Jul 29, 2026
Merged

Fix signed number after ')' or ']' being lexed as a literal#287
git-hulk merged 1 commit into
AfterShip:masterfrom
therealpandey:fix/signed-number-after-bracket

Conversation

@therealpandey

@therealpandey therealpandey commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #286.

The lexer decides whether +/- is a sign or a binary operator by looking at the previous token, but the set of tokens that can end an expression didn't include ) or ]. So SELECT (1)-1 lexed -1 as a signed literal and the parser saw two expressions with no operator between them, rejecting SQL that ClickHouse accepts.

Added TokenKindRParen and TokenKindRBracket to that set, plus a test and a fixture covering the paren, array-index and function-call forms.

SELECT (1)-1                                     -- was: <EOF> or ';' was expected, but got: "-1"
SELECT arr[1]-1
SELECT (toUnixTimestamp(now())-3600)*1000000000  -- was: expected ')', but got '<int>'

+/- after an opening bracket is still treated as a sign, so arr[-1] is unchanged. No existing golden files changed.

…p#286)

`Lexer.hasPrecedenceToken` decides whether a `+`/`-` is a sign or a binary
operator by looking at the previous token, but its set omitted the closing
brackets. `(1)-1` and `arr[1]-1` therefore lexed `-1` as a signed literal,
leaving two adjacent expressions with no operator, so valid ClickHouse SQL
was rejected.

Add `TokenKindRParen` and `TokenKindRBracket` to the set, since a closing
bracket ends an expression just like an identifier or a number does.
@aftership-abas
aftership-abas self-requested a review July 29, 2026 09:03
@therealpandey
therealpandey force-pushed the fix/signed-number-after-bracket branch from 0810bdc to 1d7f2d2 Compare July 29, 2026 09:03
@git-hulk
git-hulk removed the request for review from aftership-abas July 29, 2026 09:05
aftership-abas

This comment was marked as low quality.

@AfterShip AfterShip deleted a comment from aftership-abas Jul 29, 2026

@git-hulk git-hulk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@git-hulk
git-hulk merged commit dd867a1 into AfterShip:master Jul 29, 2026
1 check passed
@git-hulk

Copy link
Copy Markdown
Member

@therealpandey Thank you!

@therealpandey

Copy link
Copy Markdown
Contributor Author

That's an amazing turnaround time @git-hulk!

You'll be seeing more of me in this repo :). I'll follow the same process:

  1. Create an issue with a proposed fix.
  2. Wait for your approval.
  3. Raise a PR for the fix.

@git-hulk

Copy link
Copy Markdown
Member

@therealpandey Thanks! As a SigNoz user, I'm very happy and honored to see this happen. Looks forward to your contributions!

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.

[bug] signed numeric literal after ')' or ']' is treated as a literal instead of a binary operator

3 participants