[Git][ghc/ghc][wip/romes/ghci-prelude-is-implicit] fix: Mark ghci Prelude import as implicit

Rodrigo Mesquita (@alt-romes) gitlab at gitlab.haskell.org
Mon Feb 13 13:47:50 UTC 2023



Rodrigo Mesquita pushed to branch wip/romes/ghci-prelude-is-implicit at Glasgow Haskell Compiler / GHC


Commits:
6379c129 by romes at 2023-02-13T13:47:13+00:00
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

- - - - -


4 changed files:

- ghc/GHCi/UI.hs
- testsuite/tests/ghci/scripts/ghci038.stdout
- + testsuite/tests/ghci/should_run/T22829.hs
- testsuite/tests/ghci/should_run/all.T


Changes:

=====================================
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 at 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


=====================================
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]


=====================================
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 ()


=====================================
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, [''])



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6379c129157eaf516ecc031677b81f24477109b3

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/6379c129157eaf516ecc031677b81f24477109b3
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230213/246c160f/attachment-0001.html>


More information about the ghc-commits mailing list