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

Make predicate with missing capture return true #164

Merged
merged 1 commit into from
Nov 12, 2023

Conversation

jhandley
Copy link
Contributor

@jhandley jhandley commented Oct 7, 2023

If a predicate in a query references a capture that was not matched because it was optional in the query, return true rather than throw an error. In other words, if the capture was not found, ignore the predicate entirely.

This matches the behavior of tree-sitter CLI and the playground. It is not a common case but we have run into the issue matching Kotlin functions where the return type of a function is optional in the grammar requiring us to do additional filtering in the app code after the query.

@amaanq
Copy link
Member

amaanq commented Nov 12, 2023

Makes sense, thanks for the fix! Sorry for the delay in review :)

@amaanq
Copy link
Member

amaanq commented Nov 12, 2023

ASAN isn't happy

If a predicate in a query references a capture that was not matched
because it was optional in the query, return true rather than throw an
error. In other words, if the capture was not found, ignore the
predicate entirely.

This matches the behavior of tree-sitter CLI and the playground. It
 is not a common case but we have run into the issue matching Kotlin functions
where the return type of a function is optional in the grammar requiring
us to do additional filtering in the app code after the query.
@amaanq amaanq merged commit 31dd055 into tree-sitter:master Nov 12, 2023
26 checks passed
@amaanq
Copy link
Member

amaanq commented Nov 12, 2023

Thanks for the PR!

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.

2 participants