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

let with no bindings in do notation causes parse error #368

Closed
bucklereed opened this issue Jul 27, 2017 · 10 comments
Closed

let with no bindings in do notation causes parse error #368

bucklereed opened this issue Jul 27, 2017 · 10 comments

Comments

@bucklereed
Copy link

$ cat Test.hs 
foo = do
  let
  Just 3

bar :: ()
bar = ()
$ hlint --version
HLint v2.0.9, (C) Neil Mitchell 2006-2017
$ hlint Test.hs
Test.hs:5:1: Error: Parse error
Found:
      Just 3
    
  > bar :: ()
    bar = ()
  

1 hint
$ ghci Test.hs 
GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( Test.hs, interpreted )
Ok, modules loaded: Main.

It's weird, but apparently valid according to GHC.

@ndmitchell
Copy link
Owner

Thanks for the report. I've raised it as an issue in the underlying haskell-src-exts parser at haskell-suite/haskell-src-exts#373.

@EdmundsEcho
Copy link

EdmundsEcho commented Jul 30, 2018

I hope this is a useful place to add my experience with hlint generating a parse error with a let statement. The code compiles with ghc.

tests = testSpec "The Measurements Node" $ do
  describe "Measurement" $ do
    it "Pull a measurement with the type `Rx`" $ do
      let root = Q.rootHandler h
      let query = [r| query {
          measurement(type:"Rx") { 
            measurementType
          }
      }
      |]
      response <- interpretAnonymousQuery @Q.RootQuery root query
      let expected =                                        <<<<<<<< Error: Parse error found
            object
            [ "data" .= object
              [ "measurement" .= object
                [ "measurementType" .= ("Rx" :: Text)
                ]
              ]
            ]
      toJSON (toValue response) `shouldBe` expected

The error is present with hlint versions as recent as 2.1.8

@ndmitchell
Copy link
Owner

Thanks @EdmundsEcho - probably a bug in the underlying parser HLint uses. I'll raise upstream.

@ndmitchell
Copy link
Owner

@EdmundsEcho actually an entirely different problem. You don't have QuasiQuotes in your .hs file at the top, so HLint parses with it disabled, and then it gives the error you see. If you rerun with -XQuasiQuotes it works and gives you 2 hints.

@ndmitchell
Copy link
Owner

@EdmundsEcho you also have to enable TypeApplications as well.

@EdmundsEcho
Copy link

@ndmitchell thank you for the follow-up. I tested out your idea. When I run:

stack exec -- hlint tests/ETL/Queries/SubjectTests.hs

I get the following:

screen shot 2018-08-08 at 6 54 05 pm

I have the QuasiQuotes language pragma included in the the code being parsed, and in my package.yaml file. Does hlint parse the stack configuration file?

default-extensions:
  - NoImplicitPrelude
  - OverloadedStrings
  - ScopedTypeVariables
  - RecordWildCards
  - TypeApplications
  - DataKinds
  - TypeOperators
  - DeriveGeneric
  - QuasiQuotes     <<<
  - KindSignatures
  - StandaloneDeriving

@ndmitchell
Copy link
Owner

No, it does not parse things from the package.yaml file or any .cabal files. It probably could do, and probably should do, but doesn't yet. See #479 to track adding it.

@EdmundsEcho
Copy link

Understood re parsing the stack config file. If you defined a specific task to implement the feature, I would be willing to help implement the code if you like. - E

@ndmitchell
Copy link
Owner

Task #479 is to implement the feature. I've added some notes to that ticket about how I envisaged it being implemented (but I'm not overly wedded to it).

@ndmitchell
Copy link
Owner

Confirmed works with HEAD that doesn't use HSE for parsing, so fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants