You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The GHC parser (in Haddock mode) and by extension Ormolu cannot parse modules that only contain a conditional CPP block. This is possibly an upstream issue with ghc-lib-parser, but I'm filing it here because I'm unsure as GHC compiles the file correctly.
To Reproduce
Write the following to Bug.hs:
{-# LANGUAGE CPP #-}
moduleBugwhere#ifdef flag
constant::Int
constant =1312#endif
Then run:
ormolu Bug.hs
Ormolu fails with:
Bug.hs:1:1
The GHC parser (in Haddock mode) failed:
{ErrorWithoutFlag
lexical error in pragma at character 'i'}
Expected behavior
Ormolu outputs the file unchanged.
Environment
macOS Ventura
ormolu 0.7.0.0
ghc-lib-parser 9.6.2.20230523
The text was updated successfully, but these errors were encountered:
The problem here is that rawInputStringBuffer is not pre-processed in any way, i.e. it still contains all CPP markers. It seems to be able to cope with some CPP in imports at least, e.g. this is formatted just fine, although only the first import (A) is taken into consideration:
{-# LANGUAGE CPP #-}
moduleBugwhereimportA#ifdef flag
importB#endifimportC
One straightforward approach to fix this would be to remove all CPP lines before running parseImports; we could both do it such that we remove or keep import B in this example.
Describe the bug
The GHC parser (in Haddock mode) and by extension Ormolu cannot parse modules that only contain a conditional CPP block. This is possibly an upstream issue with
ghc-lib-parser
, but I'm filing it here because I'm unsure as GHC compiles the file correctly.To Reproduce
Write the following to
Bug.hs
:Then run:
Ormolu fails with:
Expected behavior
Ormolu outputs the file unchanged.
Environment
The text was updated successfully, but these errors were encountered: