Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,828
    • Issues 4,828
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 448
    • Merge requests 448
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #18616

Closed
Open
Created Aug 27, 2020 by Levent Erkök@LeventErkokReporter

Parse error oddity

I recently came across an error message from GHC in a large chunk of code that was very confusing. I was able to distill it down to the following: (Note that the below program isn't supposed to be meaningful in any way.)

foo n = do case n of
             0 -> error "urk" [foo 0]
             _ -> y <- foo n
                  pure 4

The issue is that I forgot to put a do before y <- foo n, and it'd have been nice for GHC to point that out for me. Instead, it says:

a.hs:2:32: error:
    Parse error in pattern: foo
    Possibly caused by a missing 'do'?
  |
2 |              0 -> error "urk" [foo 0]
  |                                ^^^^^

This was a large chunk of code and the error message is really pointing to a location far from the actual location of the issue. And why would foo 0 be a pattern? That was the most confusing part.

Perhaps not a big deal, but I thought I'd file a ticket to see if it can be improved. I noticed that the error message wildly changes by modifications to this source: For instance, if you delete the do in the very first line, you get a much better error message instead:

a.hs:3:21: error:
    parse error on input ‘<-’
    Perhaps this statement should be within a 'do' block?
  |
3 |              _ -> y <- foo n
  |                     ^^
Edited Aug 27, 2020 by Levent Erkök
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking