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

QuasiQuotes with # at start of line fail to parse #1564

Open
TeofilC opened this issue Feb 2, 2024 · 4 comments
Open

QuasiQuotes with # at start of line fail to parse #1564

TeofilC opened this issue Feb 2, 2024 · 4 comments

Comments

@TeofilC
Copy link

TeofilC commented Feb 2, 2024

Take the following module:

{-# LANGUAGE QuasiQuotes #-}

foo = [undefined| foo
#{_hello}|]

This features a quasiqoute that runs over several lines.
And one of those lines starts with a #, which makes it look a bit like CPP but it isn't.

HLint gives the following output:

Warning: unknown directive #{_hello}|]
in Test.hs  at line 4 col 1
Test.hs:(3,18)-(5,0): Error: Parse error: Test.hs:3:18: error: [GHC-21231]
    unterminated quasiquotation at end of input
Found:
    {-# LANGUAGE QuasiQuotes #-}

  > foo = [undefined| foo

Yet GHC correctly parses this. (Though the use of undefined then gives us an error later)

@TeofilC TeofilC changed the title QuasiQuoters fail to parse QuasiQuoters with fail to parse Feb 2, 2024
@TeofilC TeofilC changed the title QuasiQuoters with fail to parse QuasiQuoters with # at start of line fail to parse Feb 2, 2024
@TeofilC TeofilC changed the title QuasiQuoters with # at start of line fail to parse QuasiQuotes with # at start of line fail to parse Feb 2, 2024
@shayne-fletcher
Copy link
Collaborator

shayne-fletcher commented Feb 2, 2024

left to itself, hlint will default enable its own selection of language extensions. apparently one of the extensions it is default enabling causes this problem. we can override this. putting -XHaskell98 overcomes the parse error.

update: i guess it's CPP that is getting default enabled. -XNoCPP also overcomes the parse failure.

@TeofilC
Copy link
Author

TeofilC commented Feb 2, 2024

Excellent yes it does look like CPP is to blame

@shayne-fletcher
Copy link
Collaborator

what's happening is that when CPP is enabled, hlint runs a cpp preprocessor. when it does that, after preprocessing the resulting program is

foo = [undefined| foo

which is indeed an unterminated quasiquote. another workaround is to put a leading space before the # e.g.

{-# LANGUAGE QuasiQuotes #-}

foo = [undefined| foo
 #{_hello}|]

@TeofilC
Copy link
Author

TeofilC commented Feb 2, 2024

Thanks! I'm not sure if this ticket should be closed now.

I guess the missing piece is that if another user runs into this, they'd have to search to find these workarounds.
I'm not sure if hlint could direct them towards them somehow

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

No branches or pull requests

2 participants