haskellemacsghcflymake

ghc/flymake hangs on preprocessor directives


I'm using flymake(-ghc) on emacs (prelude setup, before anybody wonders, no extra configuration) for a yesod project which has some #if's here and there by default. All good apart from the fact that flymake shows this error:

/path/to/Import.hs:18:2:
    lexical error at character 'i'

and the line is precisely

#if __GLASGOW_HASKELL__ >= 704

so, exactly the same behaviour as ghci:

Prelude> #if something

<interactive>:2:2: lexical error at character 'i'

is there anything I'm missing here?

bonus: auto-complete doesn't work either (emacs, prelude, default setup etc.): it works for other things (e.g. R).


Solution

  • I presume this flymake-ghc thing does not enable the C preprocessor while checking. To fix it, add the following to the top of affected Haskell files::

    {-# LANGUAGE CPP #-}
    

    This pragma enables the preprocessor for the containing file.

    Generally, that's actually the preferred way to enable Haskell language options and extensions, because this way they are confined to files that actually require them.