diff options
author | Rik Steenkamp <rik@ewps.nl> | 2016-01-09 18:15:45 +0100 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-01-09 18:15:56 +0100 |
commit | a84c21ebaa5c56a222d69f245ef4daa77054fdcb (patch) | |
tree | 8caf065006ea917f0a7407ba7c55258ad2f39fa1 /ghc | |
parent | 0dc230879ae2f8b7f6d97779631ba0847e415f24 (diff) | |
download | haskell-a84c21ebaa5c56a222d69f245ef4daa77054fdcb.tar.gz |
Reject import declaration with semicolon in GHCi
Now GHCi rejects input containing an import declaration and semicolon,
and prints an appropriate error message. Before, the stuff after an
import declaration and semicolon got ignored (most of the time), without
telling the user about it. As the default behaviour of GHCi is to reject
multiple commands in a single input, we extend this behaviour to import
commands.
This patch fixes #10663.
(See https://phabricator.haskell.org/D1518 for the introduction of
`is_import` and `is_decl`.)
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D1726
GHC Trac Issues: #10663
Diffstat (limited to 'ghc')
-rw-r--r-- | ghc/GHCi/UI.hs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs index 7bd9bbeb77..1303af554f 100644 --- a/ghc/GHCi/UI.hs +++ b/ghc/GHCi/UI.hs @@ -933,12 +933,21 @@ enqueueCommands cmds = do runStmt :: String -> SingleStep -> GHCi (Maybe GHC.ExecResult) runStmt stmt step = do dflags <- GHC.getInteractiveDynFlags - if | GHC.isStmt dflags stmt -> run_stmt - | GHC.isImport dflags stmt -> run_imports - | otherwise -> run_decl + if | GHC.isStmt dflags stmt -> run_stmt + | GHC.isImport dflags stmt -> run_import + -- Every import declaration should be handled by `run_import`. As GHCi + -- in general only accepts one command at a time, we simply throw an + -- exception when the input contains multiple commands of which at least + -- one is an import command (see #10663). + | GHC.hasImport dflags stmt -> throwGhcException + (CmdLineError "error: expecting a single import declaration") + -- Note: `GHC.isDecl` returns False on input like + -- `data Infix a b = a :@: b; infixl 4 :@:` + -- and should therefore not be used here. + | otherwise -> run_decl where - run_imports = do + run_import = do addImportToContext stmt return (Just (GHC.ExecComplete (Right []) 0)) |