diff options
author | M Farkas-Dyck <strake888@proton.me> | 2022-09-29 01:03:13 -0800 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2022-10-19 10:46:29 -0400 |
commit | 83638dce4e20097b9b7073534e488a92dce6e88f (patch) | |
tree | e18b4b2484354c8875914a4b35a37d0377258eb4 /compiler/GHC/Iface | |
parent | f7b7a3122185222d5059e37315991afcf319e43c (diff) | |
download | haskell-83638dce4e20097b9b7073534e488a92dce6e88f.tar.gz |
Scrub various partiality involving lists (again).
Lets us avoid some use of `head` and `tail`, and some panics.
Diffstat (limited to 'compiler/GHC/Iface')
-rw-r--r-- | compiler/GHC/Iface/Ext/Ast.hs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/compiler/GHC/Iface/Ext/Ast.hs b/compiler/GHC/Iface/Ext/Ast.hs index 61a88fc4c7..8f97f51833 100644 --- a/compiler/GHC/Iface/Ext/Ast.hs +++ b/compiler/GHC/Iface/Ext/Ast.hs @@ -23,7 +23,7 @@ module GHC.Iface.Ext.Ast ( mkHieFile, mkHieFileWithSource, getCompressedAsts, en import GHC.Utils.Outputable(ppr) -import GHC.Prelude +import GHC.Prelude hiding ( head, init, last, tail ) import GHC.Types.Avail ( Avails ) import GHC.Data.Bag ( Bag, bagToList ) @@ -71,7 +71,8 @@ import qualified Data.Set as S import Data.Data ( Data, Typeable ) import Data.Foldable ( toList ) import Data.Functor.Identity ( Identity(..) ) -import Data.List.NonEmpty ( NonEmpty(..) ) +import Data.List.NonEmpty ( NonEmpty(..), nonEmpty ) +import qualified Data.List.NonEmpty as NE import Data.Void ( Void, absurd ) import Control.Monad ( forM_ ) import Control.Monad.Trans.State.Strict @@ -334,10 +335,11 @@ enrichHie ts (hsGrp, imports, exports, docs) ev_bs insts tcs = Nothing -> pure () Just c -> forM_ (classSCSelIds c) $ \v -> addUnlocatedEvBind v (EvidenceVarBind (EvInstBind True (className c)) ModuleScope Nothing) - let spanFile file children = case children of - [] -> realSrcLocSpan (mkRealSrcLoc file 1 1) - _ -> mkRealSrcSpan (realSrcSpanStart $ nodeSpan $ head children) - (realSrcSpanEnd $ nodeSpan $ last children) + let spanFile file children = case nonEmpty children of + Nothing -> realSrcLocSpan (mkRealSrcLoc file 1 1) + Just children -> mkRealSrcSpan + (realSrcSpanStart $ nodeSpan (NE.head children)) + (realSrcSpanEnd $ nodeSpan (NE.last children)) flat_asts = concat [ tasts |