@@ -227,9 +227,23 @@ elabClauses info fc opts n_in cs = let n = liftname info n_in in
227 pcover <-
227 pcover <-
229 then do missing <- genClauses fc n (map fst pdef) cs
229 then do missing <- genClauses fc n (map fst pdef) cs
230− missing' <- filterM (checkPossible info fc True n) missing
230+ poss <- mapM (checkPossible info fc True n) missing
231+ let missing' = mapMaybe id poss
231− logLvl 5 $ "Must be unreachable: " ++ show missing' ++ " from " ++ show missing
232+ logLvl 3 $ "Must be unreachable: " ++ show missing' ++ " from " ++ show missing
232− return (null missing')
233+ if null missing'
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)
243+-- let untree@(CaseDef _ sc _) = simpleCase tcase True
244+-- (pdef ++ [(mlhs, mrhs)])
245+-- logLvl 5 $ "Tree is " ++ show sc
233 else return False
247 else return False
234 pdef' <- applyOpts pdef
248 pdef' <- applyOpts pdef
235 let tree@(CaseDef _ sc _) = simpleCase tcase pcover pdef
249 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
263 tcase pcover pdef pdef' ty)
277 tcase pcover pdef pdef' ty)
264 addIBC (IBCDef n)
278 addIBC (IBCDef n)
265 setTotality n tot
279 setTotality n tot
266− when (tot == Unchecked) $ totcheck (fc, n)
280+ if (tot == Unchecked) then totcheck (fc, n)
281+ else addIBC (IBCTotal n tot)
268 case lookupDef Nothing n (tt_ctxt i) of
283 case lookupDef Nothing n (tt_ctxt i) of
269 (CaseOp _ _ _ _ sc _ _ : _) ->
284 (CaseOp _ _ _ _ sc _ _ : _) ->
@@ -301,7 +316,10 @@ elabVal info aspat tm_in
301 logLvl 2 (show vtm)
316 logLvl 2 (show vtm)
302 recheckC ctxt (FC "prompt" 0) [] vtm
317 recheckC ctxt (FC "prompt" 0) [] vtm
319+-- checks if the clause is a possible left hand side. Returns the term if
320+-- possible, otherwise Nothing.
304−checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris Bool
322+checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris (Maybe Term)
305checkPossible info fc tcgen fname lhs_in
323checkPossible info fc tcgen fname lhs_in
306 = do ctxt <- getContext
324 = do ctxt <- getContext
@@ -312,15 +330,16 @@ checkPossible info fc tcgen fname lhs_in
312 OK ((lhs', _, _), _) ->
330 OK ((lhs', _, _), _) ->
313 do let lhs_tm = orderPats (getInferTerm lhs')
331 do let lhs_tm = orderPats (getInferTerm lhs')
314 b <- inferredDiff fc (delab' i lhs_tm True) lhs
332 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
316-- trace (show (delab' i lhs_tm True) ++ "\n" ++ show lhs) $ return (not b)
334-- trace (show (delab' i lhs_tm True) ++ "\n" ++ show lhs) $ return (not b)
317− Error _ -> return False
335+ Error _ -> return Nothing
319elabClause :: ElabInfo -> FC -> Bool -> PClause -> Idris (Maybe (Term, Term))
337elabClause :: ElabInfo -> FC -> Bool -> PClause -> Idris (Maybe (Term, Term))
320elabClause info fc tcgen (PClause fname lhs_in [] PImpossible [])
338elabClause info fc tcgen (PClause fname lhs_in [] PImpossible [])
321 = do b <- checkPossible info fc tcgen fname lhs_in
339 = do b <- checkPossible info fc tcgen fname lhs_in
322− if b then fail $ show fc ++ ":" ++ show lhs_in ++ " is a possible case"
341+ Just _ -> fail $ show fc ++ ":" ++ show lhs_in ++ " is a possible case"
323− else return Nothing
342+ Nothing -> return Nothing
324elabClause info fc tcgen (PClause fname lhs_in withs rhs_in whereblock)
343elabClause info fc tcgen (PClause fname lhs_in withs rhs_in whereblock)
325 = do ctxt <- getContext
344 = do ctxt <- getContext
326 -- Build the LHS as an "Infer", and pull out its type and
345 -- 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)
471 let tm = addImpl i tm_in
490 let tm = addImpl i tm_in
472 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
491 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
473 showImp True toplhs)
492 showImp True toplhs)
474− case matchClause toplhs tm of
493+ case matchClause i toplhs tm of
475 Left _ -> fail $ show fc ++ "with clause does not match top level"
494 Left _ -> fail $ show fc ++ "with clause does not match top level"
476 Right mvars -> do logLvl 3 ("Match vars : " ++ show mvars)
495 Right mvars -> do logLvl 3 ("Match vars : " ++ show mvars)
477 lhs <- updateLHS n wname mvars ns (fullApp tm) w
496 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)
482 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
501 logLvl 2 ("Matching " ++ showImp True tm ++ " against " ++
483 showImp True toplhs)
502 showImp True toplhs)
484 withs' <- mapM (mkAuxC wname toplhs ns) withs
503 withs' <- mapM (mkAuxC wname toplhs ns) withs
485− case matchClause toplhs tm of
504+ case matchClause i toplhs tm of
486 Left _ -> fail $ show fc ++ "with clause does not match top level"
505 Left _ -> fail $ show fc ++ "with clause does not match top level"
487 Right mvars -> do lhs <- updateLHS n wname mvars ns (fullApp tm) w
506 Right mvars -> do lhs <- updateLHS n wname mvars ns (fullApp tm) w
488 return $ PWith wname lhs ws wval withs'
507 return $ PWith wname lhs ws wval withs'
@@ -797,7 +816,8 @@ checkInferred :: FC -> PTerm -> PTerm -> Idris ()
797checkInferred fc inf user =
816checkInferred fc inf user =
798 do logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
817 do logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
799 showImp True user
818 showImp True user
800− tclift $ case matchClause' True user inf of
820+ tclift $ case matchClause' True i user inf of
801 Right vs -> return ()
821 Right vs -> return ()
802 Left (x, y) -> tfail $ At fc
822 Left (x, y) -> tfail $ At fc
803 (Msg $ "The type-checked term and given term do not match: "
823 (Msg $ "The type-checked term and given term do not match: "
@@ -809,9 +829,10 @@ checkInferred fc inf user =
810inferredDiff :: FC -> PTerm -> PTerm -> Idris Bool
830inferredDiff :: FC -> PTerm -> PTerm -> Idris Bool
811inferredDiff fc inf user =
831inferredDiff fc inf user =
812− do logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
833+ logLvl 6 $ "Checked to\n" ++ showImp True inf ++ "\n" ++
813 showImp True user
834 showImp True user
814− tclift $ case matchClause' True user inf of
835+ tclift $ case matchClause' True i user inf of
815 Right vs -> return False
836 Right vs -> return False
816 Left (x, y) -> return True
837 Left (x, y) -> return True