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

Check that parameters used in parsers are by-name (or of wildcard type) #204

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

LPTK
Copy link
Contributor

@LPTK LPTK commented Nov 28, 2018

The right way of doing parameterized parsers is to use by-name parameters, as in:

def twice[T, _: P](p: => P[T]): P[(T,T)] = p ~ p

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.

@LPTK
Copy link
Contributor Author

LPTK commented Jan 12, 2019

Hey @lihaoyi. Thoughts about moving forward with this?

@lihaoyi
Copy link
Member

lihaoyi commented Jan 13, 2019

@LPTK haven't had time to properly review it yet; do you mind if I just leave this here for a while?

@LPTK
Copy link
Contributor Author

LPTK commented Jan 13, 2019

Not at all, no worries 😉

@andyczerwonka
Copy link

andyczerwonka commented Aug 21, 2019

@LPTK haven't had time to properly review it yet; do you mind if I just leave this here for a while?

This sounds like the same issue I've reported on the Gitter channel.
image

@lihaoyi is there no way to pass a collection of strings into the parser?

@milanvdm
Copy link

@lihaoyi Any progress on this?
Ive got the exact same issue that @andyczerwonka is describing: StringIn(listOfStrings:_*) fails with Function can only accept constant singleton type

@He-Pin
Copy link
Contributor

He-Pin commented Dec 7, 2024

@LPTK Any update?

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.

5 participants