Opened 8 years ago

Closed 18 months 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 Difficulty: Moderate (less than a day)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

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 8 years ago by simonmar

  • Difficulty changed from Unknown to Moderate (1 day)
  • Milestone set to _|_

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 8 years ago by simonmar

  • Priority changed from normal to low

comment:3 Changed 6 years ago by simonmar

See also #459

comment:4 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:5 Changed 6 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple

comment:6 Changed 5 years ago by simonmar

see also #3401

comment:7 Changed 5 years ago by simonmar

  • Difficulty changed from Moderate (1 day) to Moderate (less than a day)

comment:8 Changed 18 months ago by morabbin

  • Resolution set to fixed
  • Status changed from new to closed
  • Type of failure set to 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: http://www.haskell.org/ghc/  :? 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.
Prelude> 
Note: See TracTickets for help on using tickets.