Opened 5 years ago

Closed 5 years ago

#9581 closed bug (invalid)

Parse error in multiline case expression inside let inside do block

Reported by: mpopov Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.3
Keywords: Cc:
Operating System: Linux Architecture: Unknown/Multiple
Type of failure: GHC rejects valid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


main = do
    let x = case 1 of
        0 -> False
        _ -> True
    print x

The above program produces the following error: $ runghc bug.hs bug.hs:3:11: parse error on input ‘->’

Slightly rewritten versions print True as indended:

main = do
    let x = case 1 of { 0 -> False; _ -> True }
    print x

main = do
    print $ case 1 of
        0 -> False
        _ -> True

I have double-checked that the offending program does not contain mixed tabs and spaces.

The same error occurs on my own system (Linux Mint x64, Haskell Platform 2014.2 with GHC 7.83) and in FPComplete's online IDE.

I first encountered the error in a program copied verbatim from a Haskell book, so i assume that the syntax is allowed.

Change History (1)

comment:1 Changed 5 years ago by rwbarton

Resolution: invalid
Status: newclosed

This program isn't valid. let introduces layout, so because line 3's first non-whitespace character is in the same column as the first non-whitespace character after the let, lines 2-4 desugar to

let { x = case 1 of {};
      0 -> False;
      _ -> True

Lines 3 and 4 need to be indented by at least one more space for the intended meaning.

(It may help to recall that

main = do
    let x = 1
        y = 2
    print x

is valid syntax.)

Note: See TracTickets for help on using tickets.