summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorromes <rodrigo.m.mesquita@gmail.com>2023-02-13 11:43:37 +0000
committerromes <rodrigo.m.mesquita@gmail.com>2023-02-13 13:47:13 +0000
commit6379c129157eaf516ecc031677b81f24477109b3 (patch)
treef28e912cf8c728769806cf14467fe7cb9570df37
parent3c0f0c6d99486502c72e6514a40e7264baaa6afc (diff)
downloadhaskell-wip/romes/ghci-prelude-is-implicit.tar.gz
fix: Mark ghci Prelude import as implicitwip/romes/ghci-prelude-is-implicit
Fixes #22829 In GHCi, we were creating an import declaration for Prelude but we were not setting it as an implicit declaration. Therefore, ghci's import of Prelude triggered -Wmissing-import-lists. Adds regression test T22829 to testsuite
-rw-r--r--ghc/GHCi/UI.hs5
-rw-r--r--testsuite/tests/ghci/scripts/ghci038.stdout8
-rw-r--r--testsuite/tests/ghci/should_run/T22829.hs2
-rw-r--r--testsuite/tests/ghci/should_run/all.T1
4 files changed, 11 insertions, 5 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index 418502f306..58c446fb43 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -556,7 +556,10 @@ interactiveUI config srcs maybe_exprs = do
default_editor <- liftIO $ findEditor
eval_wrapper <- mkEvalWrapper default_progname default_args
- let prelude_import = simpleImportDecl preludeModuleName
+ let prelude_import =
+ case simpleImportDecl preludeModuleName of
+ -- Set to True because Prelude is implicitly imported.
+ impDecl@ImportDecl{ideclExt=ext} -> impDecl{ideclExt = ext{ideclImplicit=True}}
hsc_env <- GHC.getSession
let in_multi = length (hsc_all_home_unit_ids hsc_env) > 1
empty_cache <- liftIO newIfaceCache
diff --git a/testsuite/tests/ghci/scripts/ghci038.stdout b/testsuite/tests/ghci/scripts/ghci038.stdout
index 8a54abb760..7934cab1b5 100644
--- a/testsuite/tests/ghci/scripts/ghci038.stdout
+++ b/testsuite/tests/ghci/scripts/ghci038.stdout
@@ -1,20 +1,20 @@
-import Prelude -- implicit
+import (implicit) Prelude -- implicit
import Prelude
== map in scope due to explicit 'import Prelude'
map :: (a -> b) -> [a] -> [b]
import Prelude
== still in scope, 'import Prelude ()' is subsumed by 'import Prelude'
map :: (a -> b) -> [a] -> [b]
-import Prelude -- implicit
+import (implicit) Prelude -- implicit
== still in scope, implicit import of Prelude
map :: (a -> b) -> [a] -> [b]
import Prelude ()
== not in scope now
-import Prelude -- implicit
+import (implicit) Prelude -- implicit
x :: (a -> b) -> [a] -> [b]
:module +*Foo -- added automatically
:m -Foo
-import Prelude -- implicit
+import (implicit) Prelude -- implicit
:m +*Foo
:module +*Foo
x :: (a -> b) -> [a] -> [b]
diff --git a/testsuite/tests/ghci/should_run/T22829.hs b/testsuite/tests/ghci/should_run/T22829.hs
new file mode 100644
index 0000000000..c4276496b5
--- /dev/null
+++ b/testsuite/tests/ghci/should_run/T22829.hs
@@ -0,0 +1,2 @@
+-- Do nothing, we simply want to load Prelude in ghci with -Wmissing-import-lists and -Werror
+main = pure ()
diff --git a/testsuite/tests/ghci/should_run/all.T b/testsuite/tests/ghci/should_run/all.T
index 331ffdb726..96693241dd 100644
--- a/testsuite/tests/ghci/should_run/all.T
+++ b/testsuite/tests/ghci/should_run/all.T
@@ -87,3 +87,4 @@ test('T21300', just_ghci, ghci_script, ['T21300.script'])
test('UnliftedDataType2', just_ghci, compile_and_run, [''])
test('SizedLiterals', [req_interp, extra_files(["SizedLiteralsA.hs"]),extra_hc_opts("-O -fbyte-code-and-object-code -fprefer-byte-code")], compile_and_run, [''])
+test('T22829', just_ghci + [extra_hc_opts("-Wmissing-import-lists -Werror")], compile_and_run, [''])