Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: wrap || comparison in parenthesis when && is used #3070

Merged
merged 1 commit into from Feb 24, 2024

Conversation

amaanq
Copy link
Member

@amaanq amaanq commented Feb 23, 2024

Subtle bug that probably didn't have any side effects, but better safe than sorry

I noticed this in tree-sitter-python when building the rust crate:

warning: tree-sitter-python@0.20.4: src/parser.c: In function ‘ts_lex’:
warning: tree-sitter-python@0.20.4: src/parser.c:8359:16: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
warning: tree-sitter-python@0.20.4:  8359 |       if (!eof && lookahead == 0 ||
warning: tree-sitter-python@0.20.4:       |           ~~~~~^~~~~~~~~~~~~~~~~

this code is probably not intended to be generated like this:

case 26:
      if (!eof && lookahead == 0 ||
          lookahead == '\n') ADVANCE(168);

It reads as if ((!eof && lookahead == 0) || lookahead == '\n') when it should be if (!eof && (lookahead == 0 || lookahead == '\n'))

@amaanq amaanq force-pushed the or-cmp branch 2 times, most recently from 9fb7ab8 to 29fdb56 Compare February 23, 2024 22:43
@amaanq amaanq merged commit 32c23b6 into tree-sitter:master Feb 24, 2024
12 of 13 checks passed
@slackner
Copy link
Contributor

@amaanq I believe your change caused a regression. Please check #3274 with a suggested fix.

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.

None yet

2 participants