summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorMorrow <themorrowm@gmail.com>2021-10-04 02:30:47 +0300
committerZubin <zubin.duggal@gmail.com>2021-11-17 11:14:37 +0000
commit7850142c09090a2eef1e1b0281acd641e843356a (patch)
tree962450cf647b18af467fe890bb212cf2ce759d59 /compiler
parent16d86b97ee3056b54441e7dfd349477f32347a26 (diff)
downloadhaskell-7850142c09090a2eef1e1b0281acd641e843356a.tar.gz
Improve handling of import statements in GHCi (#20473)
Currently in GHCi, when given a line of user input we: 1. Attempt to parse and handle it as a statement 2. Otherwise, attempt to parse and handle a single import 3. Otherwise, check if there are imports present (and if so display an error message) 4. Otherwise, attempt to parse a module and only handle the declarations This patch simplifies the process to: Attempt to parse and handle it as a statement Otherwise, attempt to parse a module and handle the imports and declarations This means that multiple imports in a multiline are now accepted, and a multiline containing both imports and declarations is now accepted (as well as when separated by semicolons).
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/Driver/Main.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs
index 26647df369..ffc0cef89d 100644
--- a/compiler/GHC/Driver/Main.hs
+++ b/compiler/GHC/Driver/Main.hs
@@ -74,6 +74,7 @@ module GHC.Driver.Main
, hscTcRnLookupRdrName
, hscStmt, hscParseStmtWithLocation, hscStmtWithLocation, hscParsedStmt
, hscDecls, hscParseDeclsWithLocation, hscDeclsWithLocation, hscParsedDecls
+ , hscParseModuleWithLocation
, hscTcExpr, TcRnExprMode(..), hscImport, hscKcType
, hscParseExpr
, hscParseType
@@ -1937,12 +1938,17 @@ hscDecls :: HscEnv
-> IO ([TyThing], InteractiveContext)
hscDecls hsc_env str = hscDeclsWithLocation hsc_env str "<interactive>" 1
-hscParseDeclsWithLocation :: HscEnv -> String -> Int -> String -> IO [LHsDecl GhcPs]
-hscParseDeclsWithLocation hsc_env source line_num str = do
- L _ (HsModule{ hsmodDecls = decls }) <-
+hscParseModuleWithLocation :: HscEnv -> String -> Int -> String -> IO HsModule
+hscParseModuleWithLocation hsc_env source line_num str = do
+ L _ mod <-
runInteractiveHsc hsc_env $
hscParseThingWithLocation source line_num parseModule str
- return decls
+ return mod
+
+hscParseDeclsWithLocation :: HscEnv -> String -> Int -> String -> IO [LHsDecl GhcPs]
+hscParseDeclsWithLocation hsc_env source line_num str = do
+ HsModule { hsmodDecls = decls } <- hscParseModuleWithLocation hsc_env source line_num str
+ return decls
-- | Compile a decls
hscDeclsWithLocation :: HscEnv