@@ -93,6 +93,13 @@ codeLensProvider state plId (CodeLensParams _ _ (TextDocumentIdentifier uri))
93
93
codeLensProvider _ _ _ = pure $ Right $ List []
94
94
95
95
96
+ scrutinzedType :: EmptyCaseSort Type -> Maybe Type
97
+ scrutinzedType (EmptyCase ty) = pure ty
98
+ scrutinzedType (EmptyLamCase ty) =
99
+ case tacticsSplitFunTy ty of
100
+ (_, _, tys, _) -> listToMaybe tys
101
+
102
+
96
103
------------------------------------------------------------------------------
97
104
-- | The description for the empty case lens.
98
105
mkEmptyCaseLensDesc :: Type -> T. Text
@@ -119,6 +126,8 @@ graftMatchGroup ss l =
119
126
hoistGraft (runExcept . runExceptString) $ graftExprWithM ss $ \ case
120
127
L span (HsCase ext scrut mg@ _) -> do
121
128
pure $ Just $ L span $ HsCase ext scrut $ mg { mg_alts = l }
129
+ L span (HsLamCase ext mg@ _) -> do
130
+ pure $ Just $ L span $ HsLamCase ext $ mg { mg_alts = l }
122
131
(_ :: LHsExpr GhcPs ) -> pure Nothing
123
132
124
133
@@ -142,18 +151,26 @@ emptyCaseScrutinees state nfp = do
142
151
143
152
let scrutinees = traverse (emptyCaseQ . tcg_binds) tcg
144
153
for scrutinees $ \ aged@ (unTrack -> (ss, scrutinee)) -> do
145
- ty <- MaybeT $ typeCheck (hscEnv $ untrackedStaleValue hscenv) tcg' scrutinee
154
+ ty <- MaybeT
155
+ . fmap (scrutinzedType <=< sequence )
156
+ . traverse (typeCheck (hscEnv $ untrackedStaleValue hscenv) tcg')
157
+ $ scrutinee
146
158
case ss of
147
159
RealSrcSpan r -> do
148
160
rss' <- liftMaybe $ mapAgeTo tcg_map $ unsafeCopyAge aged r
149
161
pure (rss', ty)
150
162
UnhelpfulSpan _ -> empty
151
163
164
+ data EmptyCaseSort a
165
+ = EmptyCase a
166
+ | EmptyLamCase a
167
+ deriving (Eq , Ord , Show , Functor , Foldable , Traversable )
152
168
153
169
------------------------------------------------------------------------------
154
170
-- | Get the 'SrcSpan' and scrutinee of every empty case.
155
- emptyCaseQ :: GenericQ [(SrcSpan , HsExpr GhcTc )]
171
+ emptyCaseQ :: GenericQ [(SrcSpan , EmptyCaseSort ( HsExpr GhcTc ) )]
156
172
emptyCaseQ = everything (<>) $ mkQ mempty $ \ case
157
- L new_span (Case scrutinee [] ) -> pure (new_span, scrutinee)
173
+ L new_span (Case scrutinee [] ) -> pure (new_span, EmptyCase scrutinee)
174
+ L new_span (expr@ (LamCase [] )) -> pure (new_span, EmptyLamCase expr)
158
175
(_ :: LHsExpr GhcTc ) -> mempty
159
176
0 commit comments