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 operator handling with custom ops that start with /, and with ... #227

Merged
merged 2 commits into from
Sep 8, 2022

Conversation

alex-pinkus
Copy link
Owner

@alex-pinkus alex-pinkus commented Sep 8, 2022

  • Fix handling of custom operators when a slash was already consumed:

    • This logic was not working properly when the whitespace handler attempted to consume a slash already. To handle that, we give the eat_operator function some more information about the surrounding context of the possible prior character that has been eaten.
  • Don't allow a three-dot operator after a newline:

    • The Swift compiler actually doesn't allow this with any whitespace around it, but that's more annoying to accomplish. Instead, we simply hard-code the three dot operator as "invalid" if we've already crossed over an implicit semicolon boundary. Once we emit the _semi, the three-dot operator will no longer be legal anymore, so it will be missed on the next pass as well.
    • We don't add a test for this because tests for error conditions are somewhat brittle. If there are a lot more of this sort of thing, it might be worth investing in some custom infrastructure to test that certain snippets fail without having to assert exactly the failing structure.

Fixes #225

This logic was not working properly when the whitespace handler
attempted to consume a slash already. To handle that, we give the
`eat_operator` function some more information about the surrounding
context, like a possible prior character that has been eaten.
Fixes #226

The Swift compiler actually doesn't allow this with _any_ whitespace
around it, but that's more annoying to accomplish. Instead, we simply
hard-code the three dot operator as "invalid" if we've already crossed
over an implicit semicolon boundary. Once we emit the `_semi`, the
three-dot operator will no longer be legal anymore, so it will be missed
on the next pass as well.

We don't add a test for this because tests for error conditions are
somewhat brittle. If there are a lot more of this sort of thing, it
might be worth investing in some custom infrastructure to test _that_
certain snippets fail without having to assert _exactly_ the failing
structure.
@alex-pinkus alex-pinkus merged commit 551ff9a into main Sep 8, 2022
@alex-pinkus alex-pinkus deleted the fix-operator-handling-for-semgrep branch September 8, 2022 05:44
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.

1 participant