@@ -91,7 +91,7 @@ build ist info emode opts fn tm
9191 ptm <- get_term
9292 resolveTC' True True 10 g fn ist) ivs
9393
94− when (not pattern) $ solveAutos ist fn True
94+ when (not pattern) $ solveAutos ist fn False
9595
9696 tm <- get_term
9797 ctxt <- get_context
@@ -104,6 +104,8 @@ build ist info emode opts fn tm
104104 "Remaining problems:\n" ++ qshow probs) $
105105 do unify_all; matchProblems True; unifyProblems
106106
107+ when (not pattern) $ solveAutos ist fn True
108+
107109 probs <- get_probs
108110 case probs of
109111 [] -> return ()
@@ -269,8 +271,9 @@ elab ist info emode opts fn tm
269271 hs <- get_holes
270272 -- If any of the autos use variables which have recently been solved,
271273 -- have another go at solving them now.
272− mapM_ (\(a, ns) -> if any (\n -> n `elem` solved) ns && head hs /= a
273− then solveAuto ist fn False a
274+ mapM_ (\(a, (failc, ns)) ->
275+ if any (\n -> n `elem` solved) ns && head hs /= a
276+ then solveAuto ist fn False (a, failc)
274277 else return ()) as
275278
276279 itm <- if not pattern then insertImpLam ina t else return t
@@ -452,7 +455,7 @@ elab ist info emode opts fn tm
452455 (do movelast h
453456 delayElab 5 $ do
454457 hs <- get_holes
455− when (not (null hs)) $ do
458+ when (h `elem` hs) $ do
456459 focus h
457460 as'' <- doPrune as'
458461 case as'' of
@@ -1620,21 +1623,36 @@ findHighlight n = do ctxt <- get_context
16201623 "Can't find name" ++ show n
16211624
16221625-- Try again to solve auto implicits
1623−solveAuto :: IState -> Name -> Bool -> Name -> ElabD ()
1624−solveAuto ist fn ambigok n
1625− = do hs <- get_holes
1626− tm <- get_term
1627− when (n `elem` hs) $ do
1628− focus n
1629− g <- goal
1630− isg <- is_guess -- if it's a guess, we're working on it recursively, so stop
1631− when (not isg) $
1632− proofSearch' ist True ambigok 100 True Nothing fn [] []
1626+solveAuto :: IState -> Name -> Bool -> (Name, [FailContext]) -> ElabD ()
1627+solveAuto ist fn ambigok (n, failc)
1628+ = do hs <- get_holes
1629+ when (not (null hs)) $ do
1630+ env <- get_env
1631+ g <- goal
1632+ handleError cantsolve (when (n `elem` hs) $ do
1633+ focus n
1634+ isg <- is_guess -- if it's a guess, we're working on it recursively, so stop
1635+ when (not isg) $
1636+ proofSearch' ist True ambigok 100 True Nothing fn [] [])
1637+ (lift $ Error (addLoc failc
1638+ (CantSolveGoal g (map (\(n, b) -> (n, binderTy b)) env))))
1639+ return ()
1640+ where addLoc (FailContext fc f x : prev) err
1641+ = At fc (ElaboratingArg f x
1642+ (map (\(FailContext _ f' x') -> (f', x')) prev) err)
1643+ addLoc _ err = err
1644+
1645+ cantsolve (CantSolveGoal _ _) = True
1646+ cantsolve (InternalMsg _) = True
1647+ cantsolve (At _ e) = cantsolve e
1648+ cantsolve (Elaborating _ _ e) = cantsolve e
1649+ cantsolve (ElaboratingArg _ _ _ e) = cantsolve e
1650+ cantsolve _ = False
16331651
16341652solveAutos :: IState -> Name -> Bool -> ElabD ()
16351653solveAutos ist fn ambigok
16361654 = do autos <- get_autos
1637− mapM_ (solveAuto ist fn ambigok) (map fst autos)
1655+ mapM_ (solveAuto ist fn ambigok) (map (\(n, (fc, _)) -> (n, fc)) autos)
16381656
16391657trivial' ist
16401658 = trivial (elab ist toplevel ERHS [] (sMN 0 "tac")) ist
@@ -2337,6 +2355,7 @@ withErrorReflection x = idrisCatch x (\ e -> handle e >>= ierror)
23372355 -- TODO: argument-specific error handlers go here for ElaboratingArg
23382356 handle e = do ist <- getIState
23392357 logLvl 2 "Starting error reflection"
2358+ logLvl 5 (show e)
23402359 let handlers = idris_errorhandlers ist
23412360 applyHandlers e handlers
23422361 getFnHandlers :: Name -> Name -> Idris [Name]