[GHC] #11188: Confusing "parse error in pattern" for spurious indentation.

GHC ghc-devs at haskell.org
Wed Mar 14 06:17:37 UTC 2018


#11188: Confusing "parse error in pattern" for spurious indentation.
-------------------------------------+-------------------------------------
        Reporter:  andreas.abel      |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  high              |            Milestone:
       Component:  Compiler          |              Version:  7.10.1
  (Parser)                           |
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect         |  Unknown/Multiple
  warning at compile-time            |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #984              |  Differential Rev(s):  Phab:D4497
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Ömer Sinan Ağacan <omeragacan@…>):

 In [changeset:"cb6d8589c83247ec96d5faa82df3e93f419bbfe0/ghc" cb6d858/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="cb6d8589c83247ec96d5faa82df3e93f419bbfe0"
 Slighly improve infix con app pattern errors

 Given this program:

     main = do
       f $ do
         a <- return 3
           c <- do
           return 5

 GHC previously gave this error message:

     Main.hs:2:7: error:
         Parse error in pattern: do a <- return 3 c
         Possibly caused by a missing 'do'?
       |
     2 |   f $ do
       |       ^^...

 What happened is GHC considered the whole `f $ do a <- return 3 c` as a
 pattern. When parsed as an expression it becomes an infix application of
 `($)`, and GHC checks left and right hand sides before checking if `($)`
 is a valid infix constructor name, and shows the first error it got.

 If instead we first check if the infix op is valid in pattern context,
 the error message becomes much clearer:

     Main.hs:2:3: error:
         Parse error in pattern: f $ do a <- return 3 c
         Possibly caused by a missing 'do'?
       |
     2 |   f $ do
       |   ^^^^^^...

 This may not entirely fix #11188 but I think it's an improvement.

 Reviewers: bgamari

 Reviewed By: bgamari

 Subscribers: rwbarton, thomie, carter

 GHC Trac Issues: #11188

 Differential Revision: https://phabricator.haskell.org/D4497
 }}}

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


More information about the ghc-tickets mailing list