Skip to content

feat: Warn about unreachable variables#4567

Merged
clason merged 2 commits intotree-sitter:masterfrom
wetneb:4565-warn-about-unused-variables
Jul 21, 2025
Merged

feat: Warn about unreachable variables#4567
clason merged 2 commits intotree-sitter:masterfrom
wetneb:4565-warn-about-unused-variables

Conversation

@wetneb
Copy link
Contributor

@wetneb wetneb commented Jul 7, 2025

Closes #4565.

I added this warning as a println!, similarly to the existing warnings for unnecessary conflict declarations. Ideally, those should be using log::warn, but the logging system is only initialized when the user has passed -l / --log on the CLI.

Turning such warnings into logging statements would also make them easier to unit test, for instance via the testing_logger crate.

Closes tree-sitter#4565.

I added this warning as a `println!`, similarly
to the existing warnings for unnecessary conflict
declaration. Ideally, those should be a `log::warn`,
but the logging system is only initialized when the
user has passed `-l` / `--log` on the CLI.

Turning such warnings into logging statements would
also make them easier to unit test, for instance via the
`testing_logger` crate.
@wetneb wetneb force-pushed the 4565-warn-about-unused-variables branch from 8ea0852 to 2cfbaf2 Compare July 7, 2025 19:31
@clason
Copy link
Contributor

clason commented Jul 7, 2025

That sounds like a general refactor worth doing (as long as the warnings are still printed to stdout/stderr by default).

@clason clason added the parser-generation Related to `tree-sitter generate` label Jul 8, 2025
Co-authored-by: ObserverOfTime <chronobserver@disroot.org>
@clason clason merged commit 25c601b into tree-sitter:master Jul 21, 2025
18 checks passed
@clason
Copy link
Contributor

clason commented Jul 21, 2025

Hmm, this triggers false positives in tree-sitter-markdown, where a rule is defined in common.js but only used in tree-sitter-markdown_inline, not tree-sitter-markdown. (I expect similar issues arise in other split parsers.)

I think we may have to revert that until we have better (Info/Hint) output.

clason added a commit that referenced this pull request Jul 21, 2025
This reverts commit 25c601b.

Reason: Too many false positives.
clason added a commit that referenced this pull request Jul 22, 2025
This reverts commit 25c601b.

Reason: Too many false positives.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parser-generation Related to `tree-sitter generate`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Warn about unreachable variables when generating the parser

3 participants