Skip to content

parse errors with CPP #774

@robx

Description

@robx

Describe the bug
Just tested out the new 0.3.0.0 release, and I see some weird errors around CPP / #ifdef.

Parse error:

$ cat x.hs
{-# LANGUAGE CPP                  #-}

module Main where

f = do

#ifdef FOO
  putStrLn "foo"
#endif

  let msg = "yo!"
  putStrLn msg
$ ./ormolu x.hs
x.hs:12:3
  The GHC parser (in Haddock mode) failed:
  parse error (possibly incorrect indentation or mismatched brackets)

Bad indentation:

$ cat y.hs
{-# LANGUAGE CPP                  #-}

module Main where

f = do

#ifdef FOO
  putStrLn "foo"
#endif

  putStrLn msg
$ ./ormolu y.hs
{-# LANGUAGE CPP #-}

module Main where

f = do

#ifdef FOO
  putStrLn "foo"
#endif

putStrLn msg

Works:

$ cat z.hs
{-# LANGUAGE CPP                  #-}

module Main where

f = do

#ifdef FOO
  putStrLn "foo"
#endif
  putStrLn msg
$ ./ormolu z.hs 
{-# LANGUAGE CPP #-}

module Main where

f = do

#ifdef FOO
  putStrLn "foo"
#endif
  putStrLn msg

Parse error:

$ cat w.hs
{-# LANGUAGE CPP                  #-}

module Main where

f = putStrLn "foo"

{-

#ifdef FOO

#endif

-}
$ ./ormolu w.hs
w.hs:(7,1)-(9,0)
  The GHC parser (in Haddock mode) failed:
  unterminated `{-'

This is on macOS with the release binary, perhaps something went wrong with that? Seems unlikely that this would have passed the test suite?

Environment

  • OS name + version: Darwin ed 18.7.0 Darwin Kernel Version 18.7.0: Tue Jun 22 19:37:08 PDT 2021; root:xnu-4903.278.70~1/RELEASE_X86_64 x86_64
  • Version of the code:
    ormolu 0.3.0.0 HEAD 06b767c
    using ghc-lib-parser 9.0.1.20210324

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions