@@ -863,7 +863,7 @@ try' t1 t2 proofSearch
863 ps <- get_probs
863 ps <- get_probs
864 ulog <- getUnifyLog
864 ulog <- getUnifyLog
865 ivs <- get_instances
865 ivs <- get_instances
866− case prunStateT 999999 False ps t1 s of
866+ case prunStateT 999999 False ps Nothing t1 s of
867 OK ((v, _, _), s') -> do put s'
867 OK ((v, _, _), s') -> do put s'
868 return $! v
868 return $! v
869 Error e1 -> traceWhen ulog ("try failed " ++ show e1) $
869 Error e1 -> traceWhen ulog ("try failed " ++ show e1) $
@@ -906,8 +906,11 @@ tryWhen False a b = a
906-- Bool says whether it's okay to create new unification problems. If set
906-- Bool says whether it's okay to create new unification problems. If set
907-- to False, then the whole tactic fails if there are any new problems
907-- to False, then the whole tactic fails if there are any new problems
908tryAll :: [(Elab' aux a, Name)] -> Elab' aux a
908tryAll :: [(Elab' aux a, Name)] -> Elab' aux a
909−tryAll [(x, _)] = x
909+tryAll = tryAll' True
911+tryAll' :: Bool -> [(Elab' aux a, Name)] -> Elab' aux a
912+tryAll' _ [(x, _)] = x
910−tryAll xs = tryAll' [] 999999 xs
913+tryAll' constrok xs = doAll [] 999999 xs
912 cantResolve :: Elab' aux a
915 cantResolve :: Elab' aux a
913 cantResolve = lift $ tfail $ CantResolveAlts (map snd xs)
916 cantResolve = lift $ tfail $ CantResolveAlts (map snd xs)
@@ -915,44 +918,53 @@ tryAll xs = tryAll' [] 999999 xs
915 noneValid :: Elab' aux a
918 noneValid :: Elab' aux a
916 noneValid = lift $ tfail $ NoValidAlts (map snd xs)
919 noneValid = lift $ tfail $ NoValidAlts (map snd xs)
918− tryAll' :: [Elab' aux a] -> -- successes
921+ doAll :: [Elab' aux a] -> -- successes
919− Int -> -- most problems
922+ Int -> -- most problems
920− [(Elab' aux a, Name)] -> -- still to try
923+ [(Elab' aux a, Name)] -> -- still to try
921− Elab' aux a
924+ Elab' aux a
922− tryAll' [res] pmax [] = res
925+ doAll [res] pmax [] = res
923− tryAll' (_:_) pmax [] = cantResolve
926+ doAll (_:_) pmax [] = cantResolve
924− tryAll' [] pmax [] = noneValid
927+ doAll [] pmax [] = noneValid
925− tryAll' cs pmax ((x, msg):xs)
928+ doAll cs pmax ((x, msg):xs)
926 = do s <- get
929 = do s <- get
927 ps <- get_probs
930 ps <- get_probs
931+ ivs <- get_instances
928− case prunStateT pmax True ps x s of
932+ case prunStateT pmax True ps (if constrok then Nothing
933+ else Just ivs) x s of
929 OK ((v, newps, probs), s') ->
934 OK ((v, newps, probs), s') ->
930 do let cs' = if (newps < pmax)
935 do let cs' = if (newps < pmax)
931 then [do put s'; return $! v]
936 then [do put s'; return $! v]
932 else (do put s'; return $! v) : cs
937 else (do put s'; return $! v) : cs
933− tryAll' cs' newps xs
938+ doAll cs' newps xs
934 Error err -> do put s
939 Error err -> do put s
935− tryAll' cs pmax xs
940+ doAll cs pmax xs
937−-- Run an elaborator, and fail if any problems are introduced
942+-- Run an elaborator, and fail if any problems or constraints are introduced
938prunStateT
943prunStateT
947+ -> Maybe [b] -- constraints left, if we're interested
942 -> Control.Monad.State.Strict.StateT
948 -> Control.Monad.State.Strict.StateT
943 (ElabState t) TC t1
949 (ElabState t) TC t1
944 -> ElabState t
950 -> ElabState t
945 -> TC ((t1, Int, Idris.Core.Unify.Fails), ElabState t)
951 -> TC ((t1, Int, Idris.Core.Unify.Fails), ElabState t)
946−prunStateT pmax zok ps x s
952+prunStateT pmax zok ps ivs x s
947 = case runStateT x s of
953 = case runStateT x s of
948 OK (v, s'@(ES (p, _) _ _)) ->
954 OK (v, s'@(ES (p, _) _ _)) ->
949 let newps = length (problems p) - length ps
955 let newps = length (problems p) - length ps
956+ ibad = badInstances (instances p) ivs
950 newpmax = if newps < 0 then 0 else newps in
957 newpmax = if newps < 0 then 0 else newps in
951 if (newpmax > pmax || (not zok && newps > 0)) -- length ps == 0 && newpmax > 0))
958 if (newpmax > pmax || (not zok && newps > 0)) -- length ps == 0 && newpmax > 0))
952 then case reverse (problems p) of
959 then case reverse (problems p) of
953 ((_,_,_,_,e,_,_):_) -> Error e
960 ((_,_,_,_,e,_,_):_) -> Error e
962+ then Error (InternalMsg "Constraint introduced in disambiguation")
954− else OK ((v, newpmax, problems p), s')
963+ else OK ((v, newpmax, problems p), s')
955 Error e -> Error e
964 Error e -> Error e
966+ badInstances _ Nothing = False
967+ badInstances inow (Just ithen) = length inow > length ithen
957debugElaborator :: [ErrorReportPart] -> Elab' aux a
969debugElaborator :: [ErrorReportPart] -> Elab' aux a
958debugElaborator msg = do ps <- fmap proof get
970debugElaborator msg = do ps <- fmap proof get