@@ -227,9 +227,23 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
227227 pcover <-
228228 if cov
229229 then do missing <- genClauses fc n (map fst pdef) cs
230− missing' <- filterM (checkPossible info fc True n) missing
231− logLvl 5 $ "Must be unreachable: " ++ show missing' ++ " from " ++ show missing
232− return (null missing')
230+ poss <- mapM (checkPossible info fc True n) missing
231+ let missing' = mapMaybe id poss
232+ logLvl 3 $ "Must be unreachable: " ++ show missing' ++ " from " ++ show missing
233+ if null missing'
234+ then return True
235+ else return False
236+-- -- if there's missing cases, add a catch all case. If it's
237+-- -- unreachable, we're still covering
238+-- do let mrhs = P Ref (MN 0 "reach?") undefined
239+-- let (f,as) = unApply $ depat (head missing')
240+-- let arity = length as
241+-- let mlhs = mkApp f (map (\a -> P Bound (MN a "v") undefined)
242+-- [0..arity-1])
243+-- let untree@(CaseDef _ sc _) = simpleCase tcase True
244+-- (pdef ++ [(mlhs, mrhs)])
245+-- logLvl 5 $ "Tree is " ++ show sc
246+-- return False
233247 else return False
234248 pdef' <- applyOpts pdef
235249 let tree@(CaseDef _ sc _) = simpleCase tcase pcover pdef
@@ -263,7 +277,8 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
263277 tcase pcover pdef pdef' ty)
264278 addIBC (IBCDef n)
265279 setTotality n tot
266− when (tot == Unchecked) $ totcheck (fc, n)
280+ if (tot == Unchecked) then totcheck (fc, n)
281+ else addIBC (IBCTotal n tot)
267282 i <- get
268283 case lookupDef Nothing n (tt_ctxt i) of
269284 (CaseOp _ _ _ _ sc _ _ : _) ->
@@ -301,7 +316,10 @@ elabVal info aspat tm_in
301316 logLvl 2 (show vtm)
302317 recheckC ctxt (FC "prompt" 0) [] vtm
303318
304−checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris Bool
319+-- checks if the clause is a possible left hand side. Returns the term if
320+-- possible, otherwise Nothing.
321+
322+checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris (Maybe Term)
305323checkPossible info fc tcgen fname lhs_in
306324 = do ctxt <- getContext
307325 i <- get
@@ -312,15 +330,16 @@ checkPossible info fc tcgen fname lhs_in
312330 OK ((lhs', _, _), _) ->
313331 do let lhs_tm = orderPats (getInferTerm lhs')
314332 b <- inferredDiff fc (delab' i lhs_tm True) lhs
315− return (not b)
333+ if not b then return (Just lhs_tm) else return Nothing
316334-- trace (show (delab' i lhs_tm True) ++ "\n" ++ show lhs) $ return (not b)
317− Error _ -> return False
335+ Error _ -> return Nothing
318336
319337elabClause :: ElabInfo -> FC -> Bool -> PClause -> Idris (Maybe (Term, Term))
320338elabClause info fc tcgen (PClause fname lhs_in [] PImpossible [])
321339 = do b <- checkPossible info fc tcgen fname lhs_in
322− if b then fail $ show fc ++ ":" ++ show lhs_in ++ " is a possible case"
323− else return Nothing
340+ case b of
341+ Just _ -> fail $ show fc ++ ":" ++ show lhs_in ++ " is a possible case"
342+ Nothing -> return Nothing
324343elabClause info fc tcgen (PClause fname lhs_in withs rhs_in whereblock)
325344 = do ctxt <- getContext
326345 -- Build the LHS as an "Infer", and pull out its type and
@@ -471,7 +490,7 @@ elabClause info fc tcgen (PWith fname lhs_in withs wval_in withblock)
471490 let tm = addImpl i tm_in
472491 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
473492 showImp True toplhs)
474− case matchClause toplhs tm of
493+ case matchClause i toplhs tm of
475494 Left _ -> fail $ show fc ++ "with clause does not match top level"
476495 Right mvars -> do logLvl 3 ("Match vars : " ++ show mvars)
477496 lhs <- updateLHS n wname mvars ns (fullApp tm) w
@@ -482,7 +501,7 @@ elabClause info fc tcgen (PWith fname lhs_in withs wval_in withblock)
482501 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
483502 showImp True toplhs)
484503 withs' <- mapM (mkAuxC wname toplhs ns) withs
485− case matchClause toplhs tm of
504+ case matchClause i toplhs tm of
486505 Left _ -> fail $ show fc ++ "with clause does not match top level"
487506 Right mvars -> do lhs <- updateLHS n wname mvars ns (fullApp tm) w
488507 return $ PWith wname lhs ws wval withs'
@@ -797,7 +816,8 @@ checkInferred :: FC -> PTerm -> PTerm -> Idris ()
797816checkInferred fc inf user =
798817 do logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
799818 showImp True user
800− tclift $ case matchClause' True user inf of
819+ i <- get
820+ tclift $ case matchClause' True i user inf of
801821 Right vs -> return ()
802822 Left (x, y) -> tfail $ At fc
803823 (Msg $ "The type-checked term and given term do not match: "
@@ -809,9 +829,10 @@ checkInferred fc inf user =
809829
810830inferredDiff :: FC -> PTerm -> PTerm -> Idris Bool
811831inferredDiff fc inf user =
812− do logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
832+ do i <- get
833+ logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
813834 showImp True user
814− tclift $ case matchClause' True user inf of
835+ tclift $ case matchClause' True i user inf of
815836 Right vs -> return False
816837 Left (x, y) -> return True
817838