Opened 2 years ago

Closed 2 years ago

#9914 closed bug (fixed)

Inconsistent handling of leading whitespace in GHCi

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


In GHCi, the following three lines all work as expected:

λ» let x = 1
λ» x
λ»  let x = 2 -- Note leading whitespace
λ» x
λ» data Foo = Foo
λ» :i Foo
data Foo = Foo 	-- Defined at <interactive>:6:1

However, this fails:

λ»  data Bar = Bar -- Note leading whitespace

<interactive>:8:2: parse error on input ‘data’

Change History (5)

comment:1 Changed 2 years ago by rwbarton

A simple fix would be to change `isPrefixOf` stmt to `isPrefixOf` removeSpaces stmt (or just dropWhile isSpace) in two places in InteractiveUI.runStmt.

It may be nicer to removeSpaces before calling to runStmt, but that might not work for multiline commands, not sure what kind of layout rules those have.

comment:2 Changed 2 years ago by Dr. ERDI Gergo <gergo@…>

In 707fb3aa2b058cb4245708d6a63019b3e32f795c/ghc:

Strip leading whitespace before checking if a statement looks like a declaration (fixes #9914)

comment:3 Changed 2 years ago by cactus

Milestone: 7.8.4
Status: newmerge

That's exactly what I ended up doing.

comment:4 Changed 2 years ago by thoughtpolice


7.8.4 is already done; closing.

comment:5 Changed 2 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.