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 /compiler/main/InteractiveEval.hs | |
| 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 'compiler/main/InteractiveEval.hs')
| -rw-r--r-- | compiler/main/InteractiveEval.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs index e1f2cfcbd0..013be3c07f 100644 --- a/compiler/main/InteractiveEval.hs +++ b/compiler/main/InteractiveEval.hs @@ -14,7 +14,7 @@ module InteractiveEval ( Resume(..), History(..), execStmt, ExecOptions(..), execOptions, ExecResult(..), resumeExec, runDecls, runDeclsWithLocation, - isStmt, isImport, isDecl, + isStmt, hasImport, isImport, isDecl, parseImportDecl, SingleStep(..), resume, abandon, abandonAll, @@ -89,7 +89,7 @@ import Outputable import FastString import Bag import qualified Lexer (P (..), ParseResult(..), unP, mkPState) -import qualified Parser (parseStmt, parseModule, parseDeclaration) +import qualified Parser (parseStmt, parseModule, parseDeclaration, parseImport) import System.Directory import Data.Dynamic @@ -821,15 +821,22 @@ isStmt dflags stmt = Lexer.POk _ _ -> True Lexer.PFailed _ _ -> False --- | Returns @True@ if passed string is an import declaration. -isImport :: DynFlags -> String -> Bool -isImport dflags stmt = +-- | Returns @True@ if passed string has an import declaration. +hasImport :: DynFlags -> String -> Bool +hasImport dflags stmt = case parseThing Parser.parseModule dflags stmt of Lexer.POk _ thing -> hasImports thing Lexer.PFailed _ _ -> False where hasImports = not . null . hsmodImports . unLoc +-- | Returns @True@ if passed string is an import declaration. +isImport :: DynFlags -> String -> Bool +isImport dflags stmt = + case parseThing Parser.parseImport dflags stmt of + Lexer.POk _ _ -> True + Lexer.PFailed _ _ -> False + -- | Returns @True@ if passed string is a declaration but __/not a splice/__. isDecl :: DynFlags -> String -> Bool isDecl dflags stmt = do |
