[GHC] #13765: GHC cannot parse valid Haskell98 whose first identifier is named signature

GHC ghc-devs at haskell.org
Mon May 29 00:39:23 UTC 2017


#13765: GHC cannot parse valid Haskell98 whose first identifier is named signature
-------------------------------------+-------------------------------------
           Reporter:  ezyang         |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  low            |         Milestone:
          Component:  Compiler       |           Version:  8.2.1-rc2
  (Parser)                           |
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 This no longer parses in GHC 8.2:

 {{{
 ezyang at sabre:~$ cat A.hs
 signature = 2
 ezyang at sabre:~$ ghc-8.0 -c A.hs

 A.hs:1:1: error:
     The IO action ‘main’ is not defined in module ‘Main’
 ezyang at sabre:~$ ghc-head -c A.hs

 A.hs:1:11: error:
     parse error on input ‘=’
     Perhaps you need a 'let' in a 'do' block?
     e.g. 'let x = 5' instead of 'x = 5'
   |
 1 | signature =
 }}}

 The problem is that signature is only a keyword in the module header and
 not in the rest of the code, which means that there is a shift/reduce
 conflict when you have a `signature` at the top of the module.

 This is fairly benign bug as you can only trigger it when you have no
 imports; nevertheless, we should fix it. One possibility is to have a
 completely different parser entry when you are parsing an `hsig` file so
 that `signature` never occurs in a module header when you parse a normal
 Haskell file. ISTR this was modestly more irritating to implement but
 perhaps it is still not too bad. (Note that the shift/reduce conflict
 still exists, but since you'll never declare a signature without a module
 header it is essentially irrelevant.)

 I discovered this when mpickering pointed out that adding 'signature' to
 the module header increased the number of shift reduce conflicts.
 (https://github.com/haskell-suite/haskell-src-
 exts/pull/355#issuecomment-304536290). This wasn't the case in GHC's
 parser but only accidentally: there is already a shift reduce conflict
 when you have a top-level Haddock doc block!

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


More information about the ghc-tickets mailing list