[GHC] #10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream

GHC ghc-devs at haskell.org
Wed Oct 7 13:17:15 UTC 2015


#10942: CPP pragma ignored if top comments and Opt_KeepRawTokenStream
-------------------------------------+-------------------------------------
        Reporter:  alanz             |                Owner:  alanz
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.0.1
       Component:  Compiler          |              Version:  7.10.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
-------------------------------------+-------------------------------------
Description changed by alanz:

Old description:

> HaRe sets `Opt_KeepRawTokenStream` to be able to round trip the source
> code.
>
> If we have a module starting
>
> {{{#!hs
> {-
>
> A normal comment, to check if we can still pick up the CPP directive
> after it.
>
> -}
> {-# LANGUAGE FlexibleInstances #-}
> {-# LANGUAGE CPP #-}
> -- Check that we can parse a file which requires CPP
> module BCpp where
> bob :: Int -> Int -> Int
> #if __GLASGOW_HASKELL__ > 704
> bob x y = x + y
> #else
> bob x y = x + y * 2
> #endif
>
> }}}
>
> then the call to `loadTargets` via the GHC API fails with
>
> `SourceError (lexical error at character 'i'` which is the normal error
> when `#if` is hit and CPP is not enabled.
>
> If `Opt_KeepRawTokenStream` is not set it loads without problems.
>
> Also, files using CPP but not having a top comment load properly too.

New description:

 HaRe sets `Opt_KeepRawTokenStream` to be able to round trip the source
 code.

 If we have a module starting

 {{{#!hs
 {-

 A normal comment, to check if we can still pick up the CPP directive after
 it.

 -}
 {-# LANGUAGE FlexibleInstances #-}
 {-# LANGUAGE CPP #-}
 -- Check that we can parse a file which requires CPP
 module BCpp where
 bob :: Int -> Int -> Int
 #if __GLASGOW_HASKELL__ > 704
 bob x y = x + y
 #else
 bob x y = x + y * 2
 #endif

 }}}

 then the call to `load LoadAllTargets` via the GHC API fails with

 `SourceError (lexical error at character 'i'` which is the normal error
 when `#if` is hit and CPP is not enabled.

 If `Opt_KeepRawTokenStream` is not set it loads without problems.

 Also, files using CPP but not having a top comment load properly too.

--

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/10942#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list