Opened 10 years ago

Closed 4 years ago

#999 closed bug (fixed)

Misattributed parse error in do block

Reported by: red5_2@… Owned by:
Priority: low Milestone:
Component: Compiler (Parser) Version: 6.4.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


In the following program, there is clearly an extra closing parenthesis. However, the error message doesn't point to the actual problem:

main = do x <- 1)
          return ()
-- test.hs:1:10: The last statement in a 'do' construct must be an expression

The reported error is at the beginning of the statement "x <- 1", not at the closing parenthesis. When this first happened to me, I spent a lot of time puzzling over the beginning of the statement and the indentation of various lines before I discovered the real problem.

In this example, the error could be attributed to that unmatched parenthesis. Since 'do' blocks can legitimately be enclosed in parentheses, it might be more usable if the error message could identify the locations of both the statement and the end of the 'do' block -- this would point out both potential problem locations.

Change History (8)

comment:1 Changed 10 years ago by simonmar

difficulty: UnknownModerate (1 day)
Milestone: _|_

This happens because the closing bracket ends the layout for the do-block, via Haskell's parse-error layout convention. This causes the do-block to be checked, before getting back to parsing the rest of the file.

If you use -ferror-spans, then you get the position of the start and end of the statement.

To fix this we would probably have to postpone checking the syntax of a do-expression until the renamer. This isn't easy, because the HsDo constructor already has separate fields for statements and "body" (although I'm not sure why).

This bug is very closely related to #984. I'll leave it low prio for now.

comment:2 Changed 10 years ago by simonmar

Priority: normallow

comment:3 Changed 9 years ago by simonmar

See also #459

comment:4 Changed 8 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:5 Changed 8 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:6 Changed 8 years ago by simonmar

see also #3401

comment:7 Changed 7 years ago by simonmar

difficulty: Moderate (1 day)Moderate (less than a day)

comment:8 Changed 4 years ago by morabbin

Resolution: fixed
Status: newclosed
Type of failure: None/Unknown

Fixed in 7.6.1:

Orac:~/work/ghc $ cat > test.hs
main = do x <- 1)
          return ()
Orac:~/work/ghc $ ghci test.hs
GHCi, version 7.6.1:  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( test.hs, interpreted )

test.hs:1:17: parse error on input `)'
Failed, modules loaded: none.
Note: See TracTickets for help on using tickets.