diff options
author | romes <rodrigo.m.mesquita@gmail.com> | 2023-02-13 11:43:37 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2023-02-14 11:34:25 -0500 |
commit | 85a1a575f9909bbfa84268a9744f22ca0f0a1593 (patch) | |
tree | 143e8577223514713fc5a577f969057b6fb8004c | |
parent | e8baecd20cbd764a081c6195959719d4c73e65a8 (diff) | |
download | haskell-85a1a575f9909bbfa84268a9744f22ca0f0a1593.tar.gz |
fix: Mark ghci Prelude import as 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.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/ghci/scripts/ghci038.stdout | 8 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/T22829.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/ghci/should_run/all.T | 1 |
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, ['']) |