Skip to content

Commit fc63808

Browse files
committed
Expr.Types.Annotated: declare pattern AnnE complete
As there is only 1 constructor to Ann & as everything is guarded by type code - there is only 1 possible pattern under that type - so it is complete. As a result GHC now sees that buttoms are superflous.
1 parent 19de123 commit fc63808

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/Nix/Expr/Types/Annotated.hs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ instance Hashable ann => Hashable1 (Ann ann)
7474
#ifdef MIN_VERSION_serialise
7575
instance (Serialise ann, Serialise a) => Serialise (Ann ann a)
7676
#endif
77+
pattern AnnE
78+
:: forall ann (g :: * -> *)
79+
. ann
80+
-> g (Fix (Compose (Ann ann) g))
81+
-> Fix (Compose (Ann ann) g)
82+
pattern AnnE ann a = Fix (Compose (Ann ann a))
83+
{-# complete AnnE #-}
7784

7885
instance NFData ann => NFData1 (Ann ann)
7986

@@ -119,9 +126,6 @@ instance Serialise r => Serialise (Compose (Ann SrcSpan) NExprF r) where
119126
decode = (Compose .) . Ann <$> decode <*> decode
120127
#endif
121128

122-
pattern AnnE :: forall ann (g :: * -> *). ann
123-
-> g (Fix (Compose (Ann ann) g)) -> Fix (Compose (Ann ann) g)
124-
pattern AnnE ann a = Fix (Compose (Ann ann a))
125129

126130
stripAnnotation :: Functor f => Fix (AnnF ann f) -> Fix f
127131
stripAnnotation = unfoldFix (annotated . getCompose . unFix)
@@ -131,33 +135,26 @@ stripAnn = annotated . getCompose
131135

132136
nUnary :: Ann SrcSpan NUnaryOp -> NExprLoc -> NExprLoc
133137
nUnary (Ann s1 u) e1@(AnnE s2 _) = AnnE (s1 <> s2) $ NUnary u e1
134-
nUnary _ _ = error "nUnary: unexpected"
135138
{-# inline nUnary #-}
136139

137140
nBinary :: Ann SrcSpan NBinaryOp -> NExprLoc -> NExprLoc -> NExprLoc
138141
nBinary (Ann s1 b) e1@(AnnE s2 _) e2@(AnnE s3 _) =
139142
AnnE (s1 <> s2 <> s3) $ NBinary b e1 e2
140-
nBinary _ _ _ = error "nBinary: unexpected"
141143

142144
nSelectLoc
143145
:: NExprLoc -> Ann SrcSpan (NAttrPath NExprLoc) -> Maybe NExprLoc -> NExprLoc
144146
nSelectLoc e1@(AnnE s1 _) (Ann s2 ats) d = case d of
145147
Nothing -> AnnE (s1 <> s2) $ NSelect e1 ats Nothing
146148
Just e2@(AnnE s3 _) -> AnnE (s1 <> s2 <> s3) $ NSelect e1 ats $ pure e2
147-
_ -> error "nSelectLoc: unexpected"
148-
nSelectLoc _ _ _ = error "nSelectLoc: unexpected"
149149

150150
nHasAttr :: NExprLoc -> Ann SrcSpan (NAttrPath NExprLoc) -> NExprLoc
151151
nHasAttr e1@(AnnE s1 _) (Ann s2 ats) = AnnE (s1 <> s2) $ NHasAttr e1 ats
152-
nHasAttr _ _ = error "nHasAttr: unexpected"
153152

154153
nApp :: NExprLoc -> NExprLoc -> NExprLoc
155154
nApp e1@(AnnE s1 _) e2@(AnnE s2 _) = AnnE (s1 <> s2) $ NBinary NApp e1 e2
156-
nApp _ _ = error "nApp: unexpected"
157155

158156
nAbs :: Ann SrcSpan (Params NExprLoc) -> NExprLoc -> NExprLoc
159157
nAbs (Ann s1 ps) e1@(AnnE s2 _) = AnnE (s1 <> s2) $ NAbs ps e1
160-
nAbs _ _ = error "nAbs: unexpected"
161158

162159
nStr :: Ann SrcSpan (NString NExprLoc) -> NExprLoc
163160
nStr (Ann s1 s) = AnnE s1 $ NStr s

0 commit comments

Comments
 (0)