Check that parameters used in parsers are by-name (or of wildcard type)#204
Open
LPTK wants to merge 2 commits intocom-lihaoyi:masterfrom
Open
Check that parameters used in parsers are by-name (or of wildcard type)#204LPTK wants to merge 2 commits intocom-lihaoyi:masterfrom
LPTK wants to merge 2 commits intocom-lihaoyi:masterfrom
Conversation
Contributor
Author
|
Hey @lihaoyi. Thoughts about moving forward with this? |
Member
|
@LPTK haven't had time to properly review it yet; do you mind if I just leave this here for a while? |
Contributor
Author
|
Not at all, no worries 😉 |
|
@lihaoyi Any progress on this? |
Contributor
|
@LPTK Any update? |
Contributor
Author
Contributor
|
@LPTK I think that's because there well need a Scala 3 part too now ? thanks for the update. |
Contributor
Author
|
Would be nice if there was a check there as well I guess (haven't tried the Scala 3 version), but that shouldn't be a requirement for adding the Scala 2 check in this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The right way of doing parameterized parsers is to use by-name parameters, as in:
However, currently nothing prevents users from not using a by-name parameter. And nothing in the API seems to imply that parser parameters should be by-name.
I made the mistake myself, and was bitten by a class-cast exception coming out of nowhere. If you're lucky, you'll get a strange warning saying "a pure expression does nothing in statement position" which hints at a problem – but you won't necessarily get that warning, and it's not sufficient for users to know how to solve the problem anyway.
This PR augments the fastparse macros with a checking pass that makes sure the parsers that come from parameters are from by-name parameters.
It's not a complete check by any means and can be subverted, but I think it's much better than nothing.