@@ -101,7 +101,8 @@ elab ist info pattern tcgen fn tm
101101 (elab' ina (PRef fc unitTy))
102102 elab' ina (PFalse fc) = elab' ina (PRef fc falseTy)
103103 elab' ina (PResolveTC (FC "HACK" _)) -- for chasing parent classes
104− = resolveTC 2 fn ist
104+ = do let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
105+ resolveTC 2 fn insts ist
105106 elab' ina (PResolveTC fc) = do c <- unique_hole (MN 0 "c")
106107 instanceArg c
107108 elab' ina (PRefl fc) = elab' ina (PApp fc (PRef fc eqCon) [pimp (MN 0 "a") Placeholder,
@@ -233,7 +234,8 @@ elab ist info pattern tcgen fn tm
233234 ivs' <- get_instances
234235 when (not pattern || (ina && not tcgen)) $
235236 mapM_ (\n -> do focus n
236− resolveTC 7 fn ist) (ivs' \\ ivs)
237+ let insts = filter tcname $ map fst (ctxtAlist (tt_ctxt ist))
238+ resolveTC 7 fn insts ist) (ivs' \\ ivs)
237239 where tcArg (n, PConstraint _ _ Placeholder) = True
238240 tcArg _ = False
239241
@@ -337,10 +339,10 @@ trivial ist = try (do elab ist toplevel False False (MN 0 "tac") (PRefl (FC "prf
337339 (MN 0 "tac") (PRef (FC "prf" 0) x))
338340 (tryAll xs)
339341
340−resolveTC :: Int -> Name -> IState -> ElabD ()
341−resolveTC 0 fn ist = fail $ "Can't resolve type class"
342−resolveTC 1 fn ist = try (trivial ist) (resolveTC 0 fn ist)
343−resolveTC depth fn ist
342+resolveTC :: Int -> Name -> [Name] -> IState -> ElabD ()
343+resolveTC 0 fn insts ist = fail $ "Can't resolve type class"
344+resolveTC 1 fn insts ist = try (trivial ist) (resolveTC 0 fn insts ist)
345+resolveTC depth fn insts ist
344346 = try (trivial ist)
345347 (do t <- goal
346348 let (tc, ttypes) = unApply t
@@ -349,7 +351,7 @@ resolveTC depth fn ist
349351-- traceWhen (depth > 6) ("GOAL: " ++ show t ++ "\nTERM: " ++ show tm) $
350352-- (tryAll (map elabTC (map fst (ctxtAlist (tt_ctxt ist)))))
351353 let depth' = if scopeOnly then 2 else depth
352− blunderbuss t depth' (map fst (ctxtAlist (tt_ctxt ist))))
354+ blunderbuss t depth' insts)
353355 where
354356 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
355357 | otherwise = (fail "Can't resolve", show n)
@@ -367,25 +369,29 @@ resolveTC depth fn ist
367369 boundVar _ = False
368370
369371 blunderbuss t d [] = lift $ tfail $ CantResolve t
370− blunderbuss t d (n:ns) | n /= fn && tcname n = try (resolve n d)
371− (blunderbuss t d ns)
372− | otherwise = blunderbuss t d ns
372+ blunderbuss t d (n:ns)
373+ | n /= fn && tcname n = try (resolve n d)
374+ (blunderbuss t d ns)
375+ | otherwise = blunderbuss t d ns
373376
374377 resolve n depth
375378 | depth == 0 = fail $ "Can't resolve type class"
376379 | otherwise
377− = do t <- goal
380+ = do t <- goal
381+ let (tc, ttypes) = unApply t
382+-- if (all boundVar ttypes) then resolveTC (depth - 1) fn insts ist
383+-- else do
378384 -- if there's a hole in the goal, don't even try
379− let imps = case lookupCtxtName Nothing n (idris_implicits ist) of
385+ let imps = case lookupCtxtName Nothing n (idris_implicits ist) of
380386 [] -> []
381387 [args] -> map isImp (snd args) -- won't be overloaded!
382− args <- apply (Var n) imps
383− tm <- get_term
384− mapM_ (\ (_,n) -> do focus n
385− resolveTC (depth - 1) fn ist)
386− (filter (\ (x, y) -> not x) (zip (map fst imps) args))
387− -- if there's any arguments left, we've failed to resolve
388− solve
388+ args <- apply (Var n) imps
389+-- traceWhen (all boundVar ttypes) ("Progress: " ++ show t ++ " with " ++ show n) $
390+ mapM_ (\ (_,n) -> do focus n
391+ resolveTC (depth - 1) fn insts ist)
392+ (filter (\ (x, y) -> not x) (zip (map fst imps) args))
393+ -- if there's any arguments left, we've failed to resolve
394+ solve
389395 where isImp (PImp p _ _ _) = (True, p)
390396 isImp arg = (False, priority arg)
391397