Skip to content

hindent changes the meaning of the formatted code #532

Description

@facundominguez

Problem

hindent changes the meaning of the formatted code, which would make unattended formatting rather dangerous.

  • I checked the issue tracker for existing issues about this problem.
  • I'm using the latest version of hindent.
$ cat test.hs
{-# LANGUAGE CPP #-}
main = print (g && f1)
  where
        f1 = h
          where
            h = True
#ifdef C1
g = g1
  where
    g1 = g2
      where
        g2 = False
#else
        g = True
#endif

#ifndef C1
g = False
#endif

$ runhaskell test.hs
True

$ hindent --version
hindent 5.2.7

$ hindent test.hs

$ runhaskell test.hs
False

Actual output haskell

{-# LANGUAGE CPP #-}

main = print (g && f1)
  where
    f1 = h
      where
        h = True
#ifdef C1
g = g1
  where
    g1 = g2
      where
        g2 = False
#else
        g = True
#endif

#ifndef C1
g = False
#endif

Perhaps there should be a way to disable parsing of CPP directives to reject this program.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions