@@ -567,7 +567,7 @@ elabPE info fc caller r =
567567-- NOTE: A lot of this is repeated for reflected definitions in Idris.Elab.Term
568568-- One day, these should be merged, but until then remember that if you edit
569569-- this you might need to edit the other version...
570−checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris Bool
570+checkPossible :: ElabInfo -> FC -> Bool -> Name -> PTerm -> Idris (Maybe PTerm)
571571checkPossible info fc tcgen fname lhs_in
572572 = do ctxt <- getContext
573573 i <- getIState
@@ -587,22 +587,29 @@ checkPossible info fc tcgen fname lhs_in
587587 let emptyPat = hasEmptyPat ctxt (idris_datatypes i) lhs_tm
588588 if emptyPat then
589589 do logElab 10 $ "Empty type in pattern "
590− return False
590+ return Nothing
591591 else
592592 case recheck (constraintNS info) ctxt' [] (forget lhs_tm) lhs_tm of
593− OK _ -> do logElab 10 $ "Valid"
594− return True
593+ OK (tm, _, _) ->
594+ do logElab 10 $ "Valid " ++ show tm ++ "\n"
595+ ++ " from " ++ show lhs
596+ return (Just (delab' i tm True True))
595597 err -> do logElab 10 $ "Conversion failure"
596− return False
598+ return Nothing
597599 -- if it's a recoverable error, the case may become possible
598600 Error err -> do logLvl 10 $ "Impossible case " ++ show err
599601 -- tcgen means that it was generated by genClauses,
600602 -- so only looking for an error. Otherwise, it
601603 -- needs to be the right kind of error (a type mismatch
602604 -- in the same family).
603− if tcgen then return (recoverableCoverage ctxt err)
604− else return (validCoverageCase ctxt err ||
605+ if tcgen then returnTm i err (recoverableCoverage ctxt err)
606+ else returnTm i err (validCoverageCase ctxt err ||
605607 recoverableCoverage ctxt err)
608+ where returnTm i err True = do logLvl 10 $ "Possibly resolvable error on " ++
609+ pshow i (fmap (normalise (tt_ctxt i) []) err)
610+ ++ " on " ++ showTmImpls lhs_in
611+ return $ Just lhs_in
612+ returnTm i err False = return $ Nothing
606613
607614-- Filter out the terms which are not well type left hand sides. Whenever we
608615-- eliminate one, also eliminate later ones which match it without checking,
@@ -617,7 +624,9 @@ checkPossibles info fc tcgen fname (lhs : rest)
617624 -- check, just remove from the next batch
618625 let rest' = filter (\x -> not (qmatch x lhs)) (take 200 rest) ++ drop 200 rest
619626 restpos <- checkPossibles info fc tcgen fname rest'
620− if not ok then return restpos else return (lhs : restpos)
627+ case ok of
628+ Nothing -> return restpos
629+ Just lhstm -> return (lhstm : restpos)
621630 where
622631 qmatch _ Placeholder = True
623632 qmatch (PApp _ f args) (PApp _ f' args')
@@ -680,12 +689,12 @@ elabClause info opts (_, PClause fc fname lhs_in [] PImpossible [])
680689 let lhs = addImpl [] i lhs_in
681690 b <- checkPossible info fc tcgen fname lhs_in
682691 case b of
683− True -> tclift $ tfail (At fc
684− (Msg $ show lhs_in ++ " is a valid case"))
685− False -> do ptm <- mkPatTm lhs_in
686− logElab 5 $ "Elaborated impossible case " ++ showTmImpls lhs ++
687− "\n" ++ show ptm
688− return (Left ptm, lhs)
692+ Just _ -> tclift $ tfail (At fc
693+ (Msg $ show lhs_in ++ " is a valid case"))
694+ Nothing -> do ptm <- mkPatTm lhs_in
695+ logElab 5 $ "Elaborated impossible case " ++ showTmImpls lhs ++
696+ "\n" ++ show ptm
697+ return (Left ptm, lhs)
689698elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as whereblock)
690699 = do let tcgen = Dictionary `elem` opts
691700 push_estack fname False