@@ -50,14 +50,14 @@ recheckC fc env t
5050 return (tm, ty)
5151
5252
53−checkDef fc ns = checkAddDef False fc ns
53+checkDef fc ns = checkAddDef False True fc ns
5454
55−checkAddDef add fc [] = return []
56−checkAddDef add fc ((n, (i, top, t)) : ns)
55+checkAddDef add toplvl fc [] = return []
56+checkAddDef add toplvl fc ((n, (i, top, t)) : ns)
5757 = do ctxt <- getContext
5858 (t', _) <- recheckC fc [] t
59− when add $ addDeferred [(n, (i, top, t, True))]
60− ns' <- checkAddDef add fc ns
59+ when add $ addDeferred [(n, (i, top, t, toplvl))]
60+ ns' <- checkAddDef add toplvl fc ns
6161 return ((n, (i, top, t')) : ns')
6262-- mapM (\(n, (i, top, t)) -> do (t', _) <- recheckC fc [] t
6363-- return (n, (i, top, t'))) ns
@@ -85,7 +85,10 @@ elabType' norm info syn doc fc opts n ty' = {- let ty' = piBind (params info) ty
8585 ((tyT, defer, is), log) <-
8686 tclift $ elaborate ctxt n (TType (UVal 0)) []
8787 (errAt "type of " n (erun fc (build i info False [] n ty)))
88− ds <- checkAddDef True fc defer
88+ ds <- checkAddDef True False fc defer
89+ -- if the type is not complete, note that we'll need to infer
90+ -- things later (for solving metavariables)
91+ when (not (null ds)) $ addTyInferred n
8992-- let ds' = map (\(n, (i, top, t)) -> (n, (i, top, t, True))) ds
9093-- addDeferred ds'
9194 mapM_ (elabCaseBlock info opts) is
@@ -1271,6 +1274,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
12711274 -- Build the LHS as an "Infer", and pull out its type and
12721275 -- pattern bindings
12731276 i <- getIState
1277+ inf <- isTyInferred fname
12741278 -- get the parameters first, to pass through to any where block
12751279 let fn_ty = case lookupTy fname (tt_ctxt i) of
12761280 [t] -> t
@@ -1284,16 +1288,25 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
12841288 logLvl 5 ("LHS: " ++ show fc ++ " " ++ showTmImpls lhs)
12851289 logLvl 4 ("Fixed parameters: " ++ show params ++ " from " ++ show (fn_ty, fn_is))
12861290
1287− ((lhs', dlhs, []), _) <-
1291+ (((lhs', dlhs, []), probs), _) <-
12881292 tclift $ elaborate ctxt (sMN 0 "patLHS") infP []
1289− (errAt "left hand side of " fname
1290− (erun fc (buildTC i info True opts fname (infTerm lhs))))
1293+ (do res <- errAt "left hand side of " fname
1294+ (erun fc (buildTC i info True opts fname (infTerm lhs)))
1295+ probs <- get_probs
1296+ return (res, probs))
1297+
1298+ when inf $ addTyInfConstraints (map (\(x,y,_,_) -> (x,y)) probs)
1299+
12911300 let lhs_tm = orderPats (getInferTerm lhs')
12921301 let lhs_ty = getInferType lhs'
12931302 logLvl 3 ("Elaborated: " ++ show lhs_tm)
12941303 logLvl 3 ("Elaborated type: " ++ show lhs_ty)
12951304
1296− (clhs_c, clhsty) <- recheckC fc [] lhs_tm
1305+ -- If we're inferring metavariables in the type, don't recheck,
1306+ -- because we're only doing this to try to work out those metavariables
1307+ (clhs_c, clhsty) <- if not inf
1308+ then recheckC fc [] lhs_tm
1309+ else return (lhs_tm, lhs_ty)
12971310 let clhs = normalise ctxt [] clhs_c
12981311
12991312 logLvl 3 ("Normalised LHS: " ++ showTmImpls (delabMV i clhs))
@@ -1328,7 +1341,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
13281341 logLvl 2 $ "RHS: " ++ showTmImpls rhs
13291342 ctxt <- getContext -- new context with where block added
13301343 logLvl 5 "STARTING CHECK"
1331− ((rhs', defer, is), _) <-
1344+ ((rhs', defer, is, probs), _) <-
13321345 tclift $ elaborate ctxt (sMN 0 "patRHS") clhsty []
13331346 (do pbinds lhs_tm
13341347 setNextName
@@ -1341,7 +1354,11 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
13411354 mapM_ (elabCaseHole aux) hs
13421355 tt <- get_term
13431356 let (tm, ds) = runState (collectDeferred (Just fname) tt) []
1344− return (tm, ds, is))
1357+ probs <- get_probs
1358+ return (tm, ds, is, probs))
1359+
1360+ when inf $ addTyInfConstraints (map (\(x,y,_,_) -> (x,y)) probs)
1361+
13451362 logLvl 5 "DONE CHECK"
13461363 logLvl 2 $ "---> " ++ show rhs'
13471364 when (not (null defer)) $ iLOG $ "DEFERRED " ++ show (map fst defer)
@@ -1361,7 +1378,9 @@ elabClause info opts (cnum, PClause fc fname lhs_in withs rhs_in whereblock)
13611378 ctxt <- getContext
13621379 logLvl 5 $ "Rechecking"
13631380 logLvl 6 $ " ==> " ++ show (forget rhs')
1364− (crhs, crhsty) <- recheckC fc [] rhs'
1381+ (crhs, crhsty) <- if not inf
1382+ then recheckC fc [] rhs'
1383+ else return (rhs', clhsty)
13651384 logLvl 6 $ " ==> " ++ show crhsty ++ " against " ++ show clhsty
13661385 case converts ctxt [] clhsty crhsty of
13671386 OK _ -> return ()