@@ -111,14 +111,21 @@ justTcExpr cc parsed = do
111
111
getExprTy :: HscEnv -> LHsExpr GhcTc -> IO (Maybe Type )
112
112
getExprTy hsc_env expr = fmap CoreUtils. exprType . snd <$> deSugarExpr hsc_env expr
113
113
114
- replacements :: LHsExpr GhcPs -> [[HsExpr GhcPs ]] -> [([SrcSpan ], LHsExpr GhcPs )]
114
+ replacements :: LHsExpr GhcPs -> [[HsExpr GhcPs ]] -> [([( SrcSpan , HsExpr GhcPs ) ], LHsExpr GhcPs )]
115
115
replacements r [] = [([] , r)]
116
116
replacements e (first_hole_fit : rest) = concat rest_fit_res
117
117
where
118
- res = map (\ (l, e) -> ([l], e)) (mapMaybe (fillHole e) first_hole_fit)
119
- (first_fit_locs, first_fit_res) = unzip res
120
- rest_fit_res = zipWith addL first_fit_locs $ map (`replacements` rest) first_fit_res
121
- addL :: [SrcSpan ] -> [([SrcSpan ], LHsExpr GhcPs )] -> [([SrcSpan ], LHsExpr GhcPs )]
118
+ -- mapMaybe', but keep the result
119
+ mapMaybe' :: (a -> Maybe b ) -> [a ] -> [(a , b )]
120
+ mapMaybe' _ [] = []
121
+ mapMaybe' f (a : as) = (case f a of Just b -> ((a, b) : ); _ -> id ) $ mapMaybe' f as
122
+ res = map (\ (e, (l, r)) -> ([(l, e)], r)) (mapMaybe' (fillHole e) first_hole_fit)
123
+ (first_fit_locs_and_e, first_fit_res) = unzip res
124
+ rest_fit_res = zipWith addL first_fit_locs_and_e $ map (`replacements` rest) first_fit_res
125
+ addL ::
126
+ [(SrcSpan , HsExpr GhcPs )] ->
127
+ [([(SrcSpan , HsExpr GhcPs )], LHsExpr GhcPs )] ->
128
+ [([(SrcSpan , HsExpr GhcPs )], LHsExpr GhcPs )]
122
129
addL srcs reses = map (first (srcs ++ )) reses
123
130
124
131
-- Translate from the old String based version to the new LHsExpr version.
@@ -307,7 +314,7 @@ repair cc tp@EProb {..} =
307
314
-- We add the context by replacing a hole in a let.
308
315
let inContext = noLoc . HsLet NoExtField e_ctxt
309
316
holeyContext = inContext hole
310
- undefContext = inContext $ noLoc $ HsVar NoExtField $ noLoc $ mkVarUnqual $ fsLit " undefined "
317
+ undefContext = inContext $ noLoc undefVar
311
318
312
319
-- We find expressions that can be used as candidates in the program
313
320
expr_cands <- getExprFitCands cc undefContext
0 commit comments