diff options
author | Bodigrim <andrew.lelechenko@gmail.com> | 2022-12-18 02:27:47 +0000 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-12-20 21:16:37 -0500 |
commit | 5d96fd5060958238d5b5c98f14a8b9221c87df93 (patch) | |
tree | b7aaf8832158d93dc82d0125ce770cbefb0fa39a /compiler/GHC/Driver/Main.hs | |
parent | 666d0ba72b946721a900ff3e803d4b73879c8fbf (diff) | |
download | haskell-5d96fd5060958238d5b5c98f14a8b9221c87df93.tar.gz |
Make GHC.Driver.Main.hscTcRnLookupRdrName to return NonEmpty
Diffstat (limited to 'compiler/GHC/Driver/Main.hs')
-rw-r--r-- | compiler/GHC/Driver/Main.hs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs index b6ff27621b..976cf12b55 100644 --- a/compiler/GHC/Driver/Main.hs +++ b/compiler/GHC/Driver/Main.hs @@ -266,6 +266,7 @@ import GHC.SysTools.BaseDir (findTopDir) import Data.Data hiding (Fixity, TyCon) import Data.List ( nub, isPrefixOf, partition ) +import qualified Data.List.NonEmpty as NE import Control.Monad import Data.IORef import System.FilePath as FilePath @@ -445,11 +446,15 @@ ioMsgMaybe' ioA = do -- ----------------------------------------------------------------------------- -- | Lookup things in the compiler's environment -hscTcRnLookupRdrName :: HscEnv -> LocatedN RdrName -> IO [Name] +hscTcRnLookupRdrName :: HscEnv -> LocatedN RdrName -> IO (NonEmpty Name) hscTcRnLookupRdrName hsc_env0 rdr_name = runInteractiveHsc hsc_env0 $ do { hsc_env <- getHscEnv - ; ioMsgMaybe $ hoistTcRnMessage $ tcRnLookupRdrName hsc_env rdr_name } + -- tcRnLookupRdrName can return empty list only together with TcRnUnknownMessage. + -- Once errors has been dealt with in hoistTcRnMessage, we can enforce + -- this invariant in types by converting to NonEmpty. + ; ioMsgMaybe $ fmap (fmap (>>= NE.nonEmpty)) $ hoistTcRnMessage $ + tcRnLookupRdrName hsc_env rdr_name } hscTcRcLookupName :: HscEnv -> Name -> IO (Maybe TyThing) hscTcRcLookupName hsc_env0 name = runInteractiveHsc hsc_env0 $ do |