[Git][ghc/ghc][wip/T23996] prevent GHCi (and runghc) from suggesting other symbols when not finding main

Jade (@Jade) gitlab at gitlab.haskell.org
Fri Jan 26 12:55:15 UTC 2024



Jade pushed to branch wip/T23996 at Glasgow Haskell Compiler / GHC


Commits:
b22cc6da by Jade at 2024-01-26T13:54:30+01:00
prevent GHCi (and runghc) from suggesting other symbols when not finding main

Fixes: #23996

- - - - -


1 changed file:

- ghc/GHCi/UI.hs


Changes:

=====================================
ghc/GHCi/UI.hs
=====================================
@@ -1622,13 +1622,24 @@ pprInfo (thing, fixity, cls_insts, fam_insts, docs)
 
 runMain :: GhciMonad m => String -> m ()
 runMain s = case toArgsNoLoc s of
-            Left err   -> liftIO (hPutStrLn stderr err)
-            Right args ->
-                do dflags <- getDynFlags
-                   let main = fromMaybe "main" (mainFunIs dflags)
-                   -- Wrap the main function in 'void' to discard its value instead
-                   -- of printing it (#9086). See Haskell 2010 report Chapter 5.
-                   doWithArgs args $ "Control.Monad.void (" ++ main ++ ")"
+              Left err   -> liftIO (hPutStrLn stderr err)
+              Right args -> doWithMain (doWithArgs args)
+  where
+    doWithMain fun = do
+      dflags  <- getDynFlags
+      let main = fromMaybe "main" (mainFunIs dflags)
+      handleSourceError printGhciException $ do
+        -- doing this will prevent the main to run when it is not in scope
+        -- this might seem useless, but it doesn't suggest other functions
+        -- to be used, which is exactly what we want here. See #23996.
+        GHC.parseName main
+
+        -- Wrap the main function in 'void' to discard its value instead
+        -- of printing it (#9086). See Haskell 2010 report Chapter 5.
+        fun $ "Control.Monad.void (" ++ main ++ ")"
+
+
+
 
 -----------------------------------------------------------------------------
 -- :run



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

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b22cc6da96a9b443f2c33c8756e66bb8b83426ea
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/20240126/e6623a5d/attachment-0001.html>


More information about the ghc-commits mailing list