@@ -510,7 +510,6 @@ elab ist info emode opts fn tm
510 g <- goal
510 g <- goal
511 hs <- get_holes
511 hs <- get_holes
512 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
512 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
513− -- let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
514 then try (resolveTC True 7 g fn ist)
513 then try (resolveTC True 7 g fn ist)
515 (movelast n)
514 (movelast n)
516 else movelast n)
515 else movelast n)
@@ -658,7 +657,6 @@ elab ist info emode opts fn tm
658 env <- get_env
657 env <- get_env
659 hs <- get_holes
658 hs <- get_holes
660 if all (\n -> not (n `elem` hs)) (freeNames g)
659 if all (\n -> not (n `elem` hs)) (freeNames g)
661− -- let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
662 then try (resolveTC False 7 g fn ist)
660 then try (resolveTC False 7 g fn ist)
663 (movelast n)
661 (movelast n)
664 else movelast n)
662 else movelast n)
@@ -1230,6 +1228,9 @@ proofSearch' ist rec ambigok depth prv top n hints
1230 proofSearch rec prv ambigok (not prv) depth
1228 proofSearch rec prv ambigok (not prv) depth
1231 (elab ist toplevel ERHS [] (sMN 0 "tac")) top n hints ist
1229 (elab ist toplevel ERHS [] (sMN 0 "tac")) top n hints ist
1231+-- Resolve type classes. This will only pick up 'normal' instances, never
1232+-- named instances (hence using 'tcname' to check it's a generated instance
1233resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
1234resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
1234resolveTC = resTC' []
1235resolveTC = resTC' []
@@ -1246,12 +1247,13 @@ resTC' tcs defaultOn depth topg fn ist
1246 (do t <- goal
1247 (do t <- goal
1247 let (tc, ttypes) = unApply t
1248 let (tc, ttypes) = unApply t
1248 scopeOnly <- needsDefault t tc ttypes
1249 scopeOnly <- needsDefault t tc ttypes
1250+ let stk = elab_stack ist
1249 let insts_in = findInstances ist t
1251 let insts_in = findInstances ist t
1250 let insts = if scopeOnly then filter chaser insts_in
1252 let insts = if scopeOnly then filter chaser insts_in
1251 else insts_in
1253 else insts_in
1252 tm <- get_term
1254 tm <- get_term
1253 let depth' = if scopeOnly then 2 else depth
1255 let depth' = if scopeOnly then 2 else depth
1254− blunderbuss t depth' insts) True
1256+ blunderbuss t depth' stk (stk ++ insts)) True
1256 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
1258 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
1257 | otherwise = (fail "Can't resolve", show n)
1259 | otherwise = (fail "Can't resolve", show n)
@@ -1278,13 +1280,13 @@ resTC' tcs defaultOn depth topg fn ist
1278 boundVar (P Bound _ _) = True
1280 boundVar (P Bound _ _) = True
1279 boundVar _ = False
1281 boundVar _ = False
1281− blunderbuss t d [] = do -- c <- get_env
1283+ blunderbuss t d stk [] = do -- c <- get_env
1282 -- ps <- get_probs
1284 -- ps <- get_probs
1283 lift $ tfail $ CantResolve topg
1285 lift $ tfail $ CantResolve topg
1284− blunderbuss t d (n:ns)
1286+ blunderbuss t d stk (n:ns)
1285− | n /= fn && tcname n = try' (resolve n d)
1287+ | n /= fn && (n `elem` stk || tcname n)
1286− (blunderbuss t d ns) True
1288+ = try' (resolve n d) (blunderbuss t d stk ns) True
1287− | otherwise = blunderbuss t d ns
1289+ | otherwise = blunderbuss t d stk ns
1289 resolve n depth
1291 resolve n depth
1290 | depth == 0 = fail $ "Can't resolve type class"
1292 | depth == 0 = fail $ "Can't resolve type class"