Commit a0fb20ba authored by Zejun Wu's avatar Zejun Wu Committed by Ben Gamari

Fix ghci crash when starting with -fno-implicit-import-qualified

`ghci -fno-implicit-import-qualified` didn't start with error message:

```
GHCi, version 8.6.2: http://www.haskell.org/ghc/  :? for help

<interactive>:1:6: error:
    Not in scope: ‘System.IO.hSetBuffering’
        No module named ‘System.IO’ is imported.

...
```

This change fixes it and update test T2452 to cover this.

Test Plan:
  TEST=T2452 make accept

harbormaster build runs

Reviewers: simonmar, bgamari, RyanGlScott

Reviewed By: simonmar

Subscribers: rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5452
parent ed69f8bd
......@@ -458,15 +458,16 @@ mkEvalWrapper progname args =
"(System.Environment.withArgs " ++ show args ++ " m)"
compileGHCiExpr :: GhcMonad m => String -> m ForeignHValue
compileGHCiExpr expr = do
hsc_env <- getSession
let dflags = hsc_dflags hsc_env
-- RebindableSyntax can wreak havoc with GHCi in several ways
-- (see #13385 and #14342 for examples), so we take care to disable it
-- for the duration of running expressions that are internal to GHCi.
no_rb_hsc_env =
hsc_env { hsc_dflags = xopt_unset dflags LangExt.RebindableSyntax }
setSession no_rb_hsc_env
res <- GHC.compileExprRemote expr
setSession hsc_env
pure res
compileGHCiExpr expr =
withTempSession mkTempSession $ GHC.compileExprRemote expr
where
mkTempSession hsc_env = hsc_env
{ hsc_dflags = (hsc_dflags hsc_env)
-- RebindableSyntax can wreak havoc with GHCi in several ways
-- (see #13385 and #14342 for examples), so we take care to disable it
-- for the duration of running expressions that are internal to GHCi.
`xopt_unset` LangExt.RebindableSyntax
-- We heavily depend on -fimplicit-import-qualified to compile expr
-- with fully qualified names without imports.
`gopt_set` Opt_ImplicitImportQualified
}
:t System.IO.hPutStrLn
:set -fimplicit-import-qualified
:t System.IO.hPutStrLn
:set -fno-implicit-import-qualified
:t System.IO.hPutStrLn
......@@ -2,3 +2,7 @@
<interactive>:1:1: error:
Not in scope: ‘System.IO.hPutStrLn’
No module named ‘System.IO’ is imported.
<interactive>:1:1: error:
Not in scope: ‘System.IO.hPutStrLn’
No module named ‘System.IO’ is imported.
System.IO.hPutStrLn
:: GHC.IO.Handle.Types.Handle -> String -> IO ()
......@@ -108,7 +108,8 @@ test('ghci062', [extra_files(['ghci062/', 'ghci062/Test.hs']),
ghci_script, ['ghci062.script'])
test('ghci063', normal, ghci_script, ['ghci063.script'])
test('T2452', normal, ghci_script, ['T2452.script'])
test('T2452', [extra_hc_opts("-fno-implicit-import-qualified")],
ghci_script, ['T2452.script'])
test('T2766', normal, ghci_script, ['T2766.script'])
test('T1914', [], ghci_script, ['T1914.script'])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment