Slighly improve infix con app pattern errors
ClosedPublic

Authored by osa1 on Mar 12 2018, 8:55 AM.

Details

Summary

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 Trac #11188 but I think it's an improvement.

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
osa1 created this revision.Mar 12 2018, 8:55 AM
osa1 updated the Trac tickets for this revision.Mar 12 2018, 8:56 AM
bgamari accepted this revision.Mar 13 2018, 1:05 PM

As discussed in the call, while this indeed isn't the whole story it is good enough.

This revision is now accepted and ready to land.Mar 13 2018, 1:05 PM
This revision was automatically updated to reflect the committed changes.