[Git][ghc/ghc][master] fix: Mark ghci Prelude import as implicit

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Tue Feb 14 16:34:50 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
85a1a575 by romes at 2023-02-14T11:34:25-05: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/85a1a575f9909bbfa84268a9744f22ca0f0a1593

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/85a1a575f9909bbfa84268a9744f22ca0f0a1593
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/20230214/4b55a238/attachment-0001.html>


More information about the ghc-commits mailing list