@@ -91,7 +91,7 @@ build ist info emode opts fn tm
9191 mapM_ (\n -> when (n `elem` hs) $
9292 do focus n
9393 g <- goal
94− try (resolveTC True 7 g fn ist)
94+ try (resolveTC True False 7 g fn ist)
9595 (movelast n)) ivs
9696 ivs <- get_instances
9797 hs <- get_holes
@@ -99,7 +99,7 @@ build ist info emode opts fn tm
9999 mapM_ (\n -> when (n `elem` hs) $
100100 do focus n
101101 g <- goal
102− resolveTC True 7 g fn ist) ivs
102+ resolveTC True True 7 g fn ist) ivs
103103 tm <- get_term
104104 ctxt <- get_context
105105 probs <- get_probs
@@ -350,7 +350,7 @@ elab ist info emode opts fn tm
350350 UType _ -> elab' ina (Just fc) (PRef fc unitTy)
351351 _ -> elab' ina (Just fc) (PRef fc unitCon)
352352 elab' ina fc (PResolveTC (FC "HACK" _ _)) -- for chasing parent classes
353− = do g <- goal; resolveTC False 5 g fn ist
353+ = do g <- goal; resolveTC False False 5 g fn ist
354354 elab' ina fc (PResolveTC fc')
355355 = do c <- getNameFrom (sMN 0 "class")
356356 instanceArg c
@@ -569,7 +569,7 @@ elab ist info emode opts fn tm
569569 g <- goal
570570 hs <- get_holes
571571 if all (\n -> n == tyn || not (n `elem` hs)) (freeNames g)
572− then try (resolveTC True 7 g fn ist)
572+ then try (resolveTC True False 7 g fn ist)
573573 (movelast n)
574574 else movelast n)
575575 (ivs' \\ ivs)
@@ -729,7 +729,7 @@ elab ist info emode opts fn tm
729729 env <- get_env
730730 hs <- get_holes
731731 if all (\n -> not (n `elem` hs)) (freeNames g)
732− then try (resolveTC False 7 g fn ist)
732+ then try (resolveTC False False 7 g fn ist)
733733 (movelast n)
734734 else movelast n)
735735 (ivs' \\ ivs)
@@ -1405,14 +1405,25 @@ proofSearch' ist rec ambigok depth prv top n hints
14051405-- Resolve type classes. This will only pick up 'normal' instances, never
14061406-- named instances (hence using 'tcname' to check it's a generated instance
14071407-- name).
1408−resolveTC :: Bool -> Int -> Term -> Name -> IState -> ElabD ()
1408+resolveTC :: Bool -- using default Int
1409+ -> Bool -- allow metavariables in the goal
1410+ -> Int -- depth
1411+ -> Term -- top level goal
1412+ -> Name -- top level function name
1413+ -> IState -> ElabD ()
14091414resolveTC = resTC' []
14101415
1411−resTC' tcs def 0 topg fn ist = fail $ "Can't resolve type class"
1412−resTC' tcs def 1 topg fn ist = try' (trivial' ist) (resolveTC def 0 topg fn ist) True
1413−resTC' tcs defaultOn depth topg fn ist
1414− = do compute
1415− g <- goal
1416+resTC' tcs def mvok 0 topg fn ist = fail $ "Can't resolve type class"
1417+resTC' tcs def mvok 1 topg fn ist = try' (trivial' ist) (resolveTC def mvok 0 topg fn ist) True
1418+resTC' tcs defaultOn mvok depth topg fn ist
1419+ = do compute
1420+ g <- goal
1421+ hs <- get_holes
1422+ let argsok = tcArgsOK g hs
1423+-- trace (show (g,hs,argsok,mvok)) $
1424+ if (not argsok && not mvok)
1425+ then lift $ tfail $ CantResolve True topg
1426+ else do
14161427 ptm <- get_term
14171428 ulog <- getUnifyLog
14181429 hs <- get_holes
@@ -1429,6 +1440,22 @@ resTC' tcs defaultOn depth topg fn ist
14291440 let depth' = if scopeOnly then 2 else depth
14301441 blunderbuss t depth' stk (stk ++ insts)) True
14311442 where
1443+ tcArgsOK ty hs | (P _ nc _, as) <- unApply ty, nc == numclass && defaultOn
1444+ = True
1445+ tcArgsOK ty hs -- if any arguments are metavariables, postpone
1446+ = let (f, as) = unApply ty in
1447+ not $ any (isMeta hs) as
1448+
1449+ isMeta :: [Name] -> Term -> Bool
1450+ isMeta ns (P _ n _) = n `elem` ns
1451+ isMeta _ _ = False
1452+
1453+ notHole hs (P _ n _, c)
1454+ | (P _ cn _, _) <- unApply c,
1455+ n `elem` hs && isConName cn (tt_ctxt ist) = False
1456+ | Constant _ <- c = not (n `elem` hs)
1457+ notHole _ _ = True
1458+
14321459 elabTC n | n /= fn && tcname n = (resolve n depth, show n)
14331460 | otherwise = (fail "Can't resolve", show n)
14341461
@@ -1456,10 +1483,13 @@ resTC' tcs defaultOn depth topg fn ist
14561483
14571484 blunderbuss t d stk [] = do -- c <- get_env
14581485 -- ps <- get_probs
1459− lift $ tfail $ CantResolve topg
1486+ lift $ tfail $ CantResolve False topg
14601487 blunderbuss t d stk (n:ns)
14611488 | n /= fn && (n `elem` stk || tcname n)
1462− = try' (resolve n d) (blunderbuss t d stk ns) True
1489+ = tryCatch (resolve n d)
1490+ (\e -> case e of
1491+ CantResolve True _ -> lift $ tfail e
1492+ _ -> blunderbuss t d stk ns)
14631493 | otherwise = blunderbuss t d stk ns
14641494
14651495 resolve n depth
@@ -1488,7 +1518,7 @@ resTC' tcs defaultOn depth topg fn ist
14881518 let got = fst (unApply t)
14891519 let depth' = if tc' `elem` tcs
14901520 then depth - 1 else depth
1491− resTC' (got : tcs) defaultOn depth' topg fn ist)
1521+ resTC' (got : tcs) defaultOn mvok depth' topg fn ist)
14921522 (filter (\ (x, y) -> not x) (zip (map fst imps) args))
14931523 -- if there's any arguments left, we've failed to resolve
14941524 hs <- get_holes
@@ -2667,11 +2697,14 @@ reflectErr (NotInjective t1 t2 t3) =
26672697 , reflect t2
26682698 , reflect t3
26692699 ]
2670−reflectErr (CantResolve t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
2700+reflectErr (CantResolve _ t) = raw_apply (Var $ reflErrName "CantResolve") [reflect t]
26712701reflectErr (CantResolveAlts ss) =
26722702 raw_apply (Var $ reflErrName "CantResolveAlts")
26732703 [rawList (Var $ reflm "TTName") (map reflectName ss)]
26742704reflectErr (IncompleteTerm t) = raw_apply (Var $ reflErrName "IncompleteTerm") [reflect t]
2705+reflectErr (NoEliminator str t)
2706+ = raw_apply (Var $ reflErrName "NoEliminator") [RConstant (Str str),
2707+ reflect t]
26752708reflectErr UniverseError = Var $ reflErrName "UniverseError"
26762709reflectErr ProgramLineComment = Var $ reflErrName "ProgramLineComment"
26772710reflectErr (Inaccessible n) = raw_apply (Var $ reflErrName "Inaccessible") [reflectName n]