@@ -510,7 +510,6 @@ elab ist info emode opts fn tm
510510 g <- goal
511511 hs <- get_holes
512512 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
513− -- let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
514513 then try (resolveTC True 7 g fn ist)
515514 (movelast n)
516515 else movelast n)
@@ -658,7 +657,6 @@ elab ist info emode opts fn tm
658657 env <- get_env
659658 hs <- get_holes
660659 if all (\n -> not (n `elem` hs)) (freeNames g)
661− -- let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
662660 then try (resolveTC False 7 g fn ist)
663661 (movelast n)
664662 else movelast n)
@@ -1230,6 +1228,9 @@ proofSearch' ist rec ambigok depth prv top n hints
12301228 proofSearch rec prv ambigok (not prv) depth
12311229 (elab ist toplevel ERHS [] (sMN 0 "tac")) top n hints ist
12321230
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
1233+-- name).
12331234resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
12341235resolveTC = resTC' []
12351236
@@ -1246,12 +1247,13 @@ resTC' tcs defaultOn depth topg fn ist
12461247 (do t <- goal
12471248 let (tc, ttypes) = unApply t
12481249 scopeOnly <- needsDefault t tc ttypes
1250+ let stk = elab_stack ist
12491251 let insts_in = findInstances ist t
12501252 let insts = if scopeOnly then filter chaser insts_in
12511253 else insts_in
12521254 tm <- get_term
12531255 let depth' = if scopeOnly then 2 else depth
1254− blunderbuss t depth' insts) True
1256+ blunderbuss t depth' stk (stk ++ insts)) True
12551257 where
12561258 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
12571259 | otherwise = (fail "Can't resolve", show n)
@@ -1278,13 +1280,13 @@ resTC' tcs defaultOn depth topg fn ist
12781280 boundVar (P Bound _ _) = True
12791281 boundVar _ = False
12801282
1281− blunderbuss t d [] = do -- c <- get_env
1283+ blunderbuss t d stk [] = do -- c <- get_env
12821284 -- ps <- get_probs
12831285 lift $ tfail $ CantResolve topg
1284− blunderbuss t d (n:ns)
1285− | n /= fn && tcname n = try' (resolve n d)
1286− (blunderbuss t d ns) True
1287− | otherwise = blunderbuss t d ns
1286+ blunderbuss t d stk (n:ns)
1287+ | n /= fn && (n `elem` stk || tcname n)
1288+ = try' (resolve n d) (blunderbuss t d stk ns) True
1289+ | otherwise = blunderbuss t d stk ns
12881290
12891291 resolve n depth
12901292 | depth == 0 = fail $ "Can't resolve type class"