Skip to content

Allow #ifdef'd pragmas

Sometimes I want to do something like

{-# LANGUAGE CPP #-}
#ifdef RUN_TESTS
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
#endif

module Foo
  where

#ifdef RUN_TESTS
import Test.QuickCheck
#endif

newtype Bar = Bar Int
#ifdef RUN_TESTS
  deriving Arbitrary
#endif

...

especially (like in that example) for embedding testing code in my modules. I want to #ifdef the pragma so that my code stays Haskell98 when it's only being used, not tested, but this doesn't seem to work.

I suppose this would require two passes of looking for pragmas if CPP was invoked; one before CPP and one after, because the -XCPP option can be invoked in a pragma.

Trac metadata
Trac field Value
Version 6.8.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler (Parser)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture Unknown
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information