Skip to content

comipleExpr or :def in GHCi rejects valid multiline expr or accepts invalid expr

dynComipleExpr will accept invalid expr or reject valid expr because it compiles the expr as "let _dynComipleExpr = (" ++ expr ++ ")".

-- tail -n 15 Test.hs
    forM_ exprs $ \expr ->
      handleSourceError printException $ do
        dyn <- dynCompileExpr expr
        liftIO $ print dyn
  where
  exprs =
    [ ""
    , "(),()"
    , "()"
    , "\"test\""
    , unlines [ "[()]"
              , " :: [()]"
              ]
    ]
-- ./Test /lib/ghc
<<()>>
<<((),())>>
<<()>>
<<[Char]>>

<interactive>:2:2:
    parse error (possibly incorrect indentation or mismatched brackets)

As :def and :cmd uses compileExpr, they have the same problem:

GHCi, version 7.10.1: http://www.haskell.org/ghc/  :? for help
Prelude> :{
Prelude| :cmd return $ unlines
Prelude|   [ "1"
Prelude|   , "2"
Prelude|   ]
Prelude| :}

<interactive>:2:3:
    parse error (possibly incorrect indentation or mismatched brackets)
Prelude> import Prelude (return, id, ShowS, IO)
Prelude> :cmd return "0"

<interactive>:1:42:
    Not in scope: type constructor or class ‘String’
Prelude> type String = ShowS
Prelude> :cmd return id
zsh: segmentation fault (core dumped)  ghci
Trac metadata
Trac field Value
Version 7.10.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component GHC API
Test case
Differential revisions
BlockedBy
Related
Blocking
CC simonmar
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information