@@ -567,7 +567,7 @@ elabPE info fc caller r =
567-- NOTE: A lot of this is repeated for reflected definitions in Idris.Elab.Term
567-- NOTE: A lot of this is repeated for reflected definitions in Idris.Elab.Term
568-- One day, these should be merged, but until then remember that if you edit
568-- One day, these should be merged, but until then remember that if you edit
569-- this you might need to edit the other version...
569-- 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)
571checkPossible info fc tcgen fname lhs_in
571checkPossible info fc tcgen fname lhs_in
572 = do ctxt <- getContext
572 = do ctxt <- getContext
573 i <- getIState
573 i <- getIState
@@ -587,22 +587,29 @@ checkPossible info fc tcgen fname lhs_in
587 let emptyPat = hasEmptyPat ctxt (idris_datatypes i) lhs_tm
587 let emptyPat = hasEmptyPat ctxt (idris_datatypes i) lhs_tm
588 if emptyPat then
588 if emptyPat then
589 do logElab 10 $ "Empty type in pattern "
589 do logElab 10 $ "Empty type in pattern "
590− return False
590+ return Nothing
592 case recheck (constraintNS info) ctxt' [] (forget lhs_tm) lhs_tm of
592 case recheck (constraintNS info) ctxt' [] (forget lhs_tm) lhs_tm of
593− OK _ -> do logElab 10 $ "Valid"
594+ do logElab 10 $ "Valid " ++ show tm ++ "\n"
595+ ++ " from " ++ show lhs
594− return True
596+ return (Just (delab' i tm True True))
595 err -> do logElab 10 $ "Conversion failure"
597 err -> do logElab 10 $ "Conversion failure"
596− return False
598+ return Nothing
597 -- if it's a recoverable error, the case may become possible
599 -- if it's a recoverable error, the case may become possible
598 Error err -> do logLvl 10 $ "Impossible case " ++ show err
600 Error err -> do logLvl 10 $ "Impossible case " ++ show err
599 -- tcgen means that it was generated by genClauses,
601 -- tcgen means that it was generated by genClauses,
600 -- so only looking for an error. Otherwise, it
602 -- so only looking for an error. Otherwise, it
601 -- needs to be the right kind of error (a type mismatch
603 -- needs to be the right kind of error (a type mismatch
602 -- in the same family).
604 -- in the same family).
603− if tcgen then return (recoverableCoverage ctxt err)
605+ if tcgen then returnTm i err (recoverableCoverage ctxt err)
604− else return (validCoverageCase ctxt err ||
606+ else returnTm i err (validCoverageCase ctxt err ||
605 recoverableCoverage ctxt err)
607 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
607-- Filter out the terms which are not well type left hand sides. Whenever we
614-- Filter out the terms which are not well type left hand sides. Whenever we
608-- eliminate one, also eliminate later ones which match it without checking,
615-- eliminate one, also eliminate later ones which match it without checking,
@@ -617,7 +624,9 @@ checkPossibles info fc tcgen fname (lhs : rest)
617 -- check, just remove from the next batch
624 -- check, just remove from the next batch
618 let rest' = filter (\x -> not (qmatch x lhs)) (take 200 rest) ++ drop 200 rest
625 let rest' = filter (\x -> not (qmatch x lhs)) (take 200 rest) ++ drop 200 rest
619 restpos <- checkPossibles info fc tcgen fname rest'
626 restpos <- checkPossibles info fc tcgen fname rest'
620− if not ok then return restpos else return (lhs : restpos)
628+ Nothing -> return restpos
629+ Just lhstm -> return (lhstm : restpos)
622 qmatch _ Placeholder = True
631 qmatch _ Placeholder = True
623 qmatch (PApp _ f args) (PApp _ f' args')
632 qmatch (PApp _ f args) (PApp _ f' args')
@@ -680,12 +689,12 @@ elabClause info opts (_, PClause fc fname lhs_in [] PImpossible [])
680 let lhs = addImpl [] i lhs_in
689 let lhs = addImpl [] i lhs_in
681 b <- checkPossible info fc tcgen fname lhs_in
690 b <- checkPossible info fc tcgen fname lhs_in
682 case b of
691 case b of
683− True -> tclift $ tfail (At fc
692+ Just _ -> tclift $ tfail (At fc
684− (Msg $ show lhs_in ++ " is a valid case"))
693+ (Msg $ show lhs_in ++ " is a valid case"))
685− False -> do ptm <- mkPatTm lhs_in
694+ Nothing -> do ptm <- mkPatTm lhs_in
686− logElab 5 $ "Elaborated impossible case " ++ showTmImpls lhs ++
695+ logElab 5 $ "Elaborated impossible case " ++ showTmImpls lhs ++
687− "\n" ++ show ptm
696+ "\n" ++ show ptm
688− return (Left ptm, lhs)
697+ return (Left ptm, lhs)
689elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as whereblock)
698elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as whereblock)
690 = do let tcgen = Dictionary `elem` opts
699 = do let tcgen = Dictionary `elem` opts
691 push_estack fname False
700 push_estack fname False