haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 210 forks source link

Doesn't work with Template Haskell #1061

Open cscalfani opened 5 years ago

cscalfani commented 5 years ago

The following code:

import Data.Aeson

data Message =
  Message {
      _id :: Text
    , _type' :: Text
    , _state :: Text
    , _status :: Text
    , _flag :: Text
    , _context :: Text
    , _created :: Text
  }
  deriving (Generic, Show)

$(ATH.deriveJSON defaultOptions {
    fieldLabelModifier = \f -> if P.last f == '\'' then P.init f else f
  } ''Message)

produces the following error:

Got error while processing diagnostics: /private/var/folders/wq/yhfgnjsj1yv9yttml8nvfcqm0000gn/T/ghc-mod3389/Api3386-714.hs:(62,3)-(64,13): Splicing declarations ATH.deriveJSON defaultOptions {fieldLabelModifier = \ f_abvrc -> if P.last f_abvrc == '\'' then P.init f_abvrc else f_abvrc} ''Message ======> instance ToJSON Message where toJSON = \ value_abvs1 -> case value_abvs1 of { Message arg1_abvs2 arg2_abvs3 arg3_abvs4 arg4_abvs5 arg5_abvs6 arg6_abvs7 arg7_abvs8 -> object [((pack "_id") .= (toJSON arg1_abvs2)), ((pack "_type") .= (toJSON arg2_abvs3)), ((pack "_state") .= (toJSON arg3_abvs4)), ((pack "_status") .= (toJSON arg4_abvs5)), ((pack "_flag") .= (toJSON arg5_abvs6)), ((pack "_context") .= (toJSON arg6_abvs7)), ((pack "_created") .= (toJSON arg7_abvs8))] } toEncoding = \ value_abvs9 -> case value_abvs9 of { Message arg1_abvsa arg2_abvsb arg3_abvsc arg4_abvsd arg5_abvse arg6_abvsf arg7_abvsg -> Data.Aeson.Encoding.Internal.wrapObject (Data.Aeson.TH.commaSep [((Data.Aeson.Encoding.Internal.string "_id") Data.Aeson.Encoding.Internal.>< (Data.Aeson.Encoding.Internal.colon Data.Aeson.Encoding.Internal.>< (toEncoding arg1_abvsa))), ((Data.Aeson.Encoding.Internal.string "_type") Data.Aeson.Encoding.Internal.>< (Data.Aeson.Encoding.Internal.colon Data.Aeson.Encoding.Internal.>< (toEncoding arg2_abvsb))), ((Data.Aeson.Encoding.Internal.string "_state") Data.Aeson.Encoding.Internal.>< (Data.Aeson.Encoding.Internal.colon Data.Aeson.Encoding.Internal.>< (toEncoding arg3_abvsc))), ((Data.Aeson.Encoding.Internal.string "_status") Data.Aeson.Encoding.Internal.>< (Data.Aeson.Encoding.Internal.colon Data.Aeson.Encoding.Internal.>< (toEncoding arg4_abvsd))), ((Data.Aeson.Encoding.Internal.string "_flag") Data.Aeson.Encoding.Internal.>< (Data.Aeson.Encoding.Internal.colon Data.Aeson.Encoding.Internal.>< (toEncoding arg5_abvse))), ((Data.Aeson.Encoding.Internal.string "_context") Data.Aeson.Encoding.Internal.>< (Data.Aeson.Encoding.Internal.colon Data.Aeson.Encoding.Internal.>< (toEncoding arg6_abvsf))), ((Data.Aeson.Encoding.Internal.string "_created") Data.Aeson.Encoding.Internal.>< (Data.Aeson.Encoding.Internal.colon Data.Aeson.Encoding.Internal.>< (toEncoding arg7_abvsg)))]) } instance FromJSON Message where parseJSON = \ value_abvsh -> case value_abvsh of Object recObj_abvsi -> (((((((Message <$> (((((Data.Aeson.TH.lookupField parseJSON) "Api.Submission.Fax.Api.Message") "Message") recObj_abvsi) (pack "_id"))) <> (((((Data.Aeson.TH.lookupField parseJSON) "Api.Submission.Fax.Api.Message") "Message") recObj_abvsi) (pack "_type"))) <> (((((Data.Aeson.TH.lookupField parseJSON) "Api.Submission.Fax.Api.Message") "Message") recObj_abvsi) (pack "_state"))) <> (((((Data.Aeson.TH.lookupField parseJSON) "Api.Submission.Fax.Api.Message") "Message") recObj_abvsi) (pack "_status"))) <> (((((Data.Aeson.TH.lookupField parseJSON) "Api.Submission.Fax.Api.Message") "Message") recObj_abvsi) (pack "_flag"))) <> (((((Data.Aeson.TH.lookupField parseJSON) "Api.Submission.Fax.Api.Message") "Message") recObj_abvsi) (pack "_context"))) <> (((((Data.Aeson.TH.lookupField parseJSON) "Api.Submission.Fax.Api.Message") "Message") recObj_abvsi) (pack "_created"))) other_abvsj -> (((Data.Aeson.TH.parseTypeMismatch' "Message") "Api.Submission.Fax.Api.Message") "Object") (Data.Aeson.TH.valueConName other_abvsj)

Commenting out the Template Haskell no longer produces the error.

I have similar errors in other TH that I'm using.

I'm using Atom if that matters.

alanz commented 5 years ago

What operating system and GHC version? There is a problem with TH on windows with GHC 8.6.3, please confirm whether this is a different issue.

And ideally provide a reproducable project that shows up the problem.

cscalfani commented 5 years ago

I'm not using Windows. I'm using OSX (High Sierra). I'm using GHC 8.2.2 and Stack 1.9.3.

cscalfani commented 5 years ago

I've tried for the last hour to create a simple example that has the problem with no luck.

My original project is a Yesod project and so I created a simple Yesod project and tried it TH there but couldn't reproduce the problem.

I tried deleting my .stack-work and rebuilding my original app but still has the problem.

Is there any other cache that I may need to delete? Turns out this project used to be used with ghc-mod whereas the newer test projects have not.