@@ -87,7 +87,7 @@ elabClauses info' fc opts n_in cs =
8787 let pats_raw = map (simple_lhs ctxt) pats_in
8888 logElab 3 $ "Elaborated patterns:\n" ++ show pats_raw
8989
90− solveDeferred n
90+ solveDeferred fc n
9191
9292 -- just ensure that the structure exists
9393 fmodifyState (ist_optimisation n) id
@@ -670,7 +670,7 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
670670 logElab 2 $ "RHS: " ++ show (map fst newargs_all) ++ " " ++ showTmImpls rhs
671671 ctxt <- getContext -- new context with where block added
672672 logElab 5 "STARTING CHECK"
673− ((rhs', defer, is, probs, ctxt', newDecls, highlights), _) <-
673+ ((rhs', defer, holes, is, probs, ctxt', newDecls, highlights), _) <-
674674 tclift $ elaborate ctxt (idris_datatypes i) (sMN 0 "patRHS") clhsty initEState
675675 (do pbinds ist lhs_tm
676676 -- proof search can use explicitly written names
@@ -687,7 +687,8 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
687687 let (tm, ds) = runState (collectDeferred (Just fname)
688688 (map fst $ case_decls aux) ctxt tt) []
689689 probs <- get_probs
690− return (tm, ds, is, probs, ctxt', newDecls, highlights))
690+ hs <- get_holes
691+ return (tm, ds, hs, is, probs, ctxt', newDecls, highlights))
691692 setContext ctxt'
692693 processTacticDecls info newDecls
693694 sendHighlighting highlights
@@ -698,9 +699,12 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
698699 logElab 4 $ "---> " ++ show rhs'
699700 when (not (null defer)) $ logElab 1 $ "DEFERRED " ++
700701 show (map (\ (n, (_,_,t,_)) -> (n, t)) defer)
701− def' <- checkDef fc (\n -> Elaborating "deferred type of " n Nothing) defer
702− let def'' = map (\(n, (i, top, t, ns)) -> (n, (i, top, t, ns, False, True))) def'
702+
703+ -- If there's holes, set the metavariables as undefinable
704+ def' <- checkDef fc (\n -> Elaborating "deferred type of " n Nothing) (null holes) defer
705+ let def'' = map (\(n, (i, top, t, ns)) -> (n, (i, top, t, ns, False, null holes))) def'
703706 addDeferred def''
707+
704708 mapM_ (\(n, _) -> addIBC (IBCDef n)) def''
705709
706710 when (not (null def')) $ do
@@ -716,11 +720,23 @@ elabClause info opts (cnum, PClause fc fname lhs_in_as withs rhs_in_as wherebloc
716720 logElab 5 $ "Rechecking"
717721 logElab 6 $ " ==> " ++ show (forget rhs')
718722
719− (crhs, crhsty) <- if not inf
720− then recheckC_borrowing True (PEGenerated `notElem` opts)
721− borrowed fc id [] rhs'
722− else return (rhs', clhsty)
723+ (crhs, crhsty) -- if there's holes && deferred things, it's okay
724+ -- but we'll need to freeze the definition and not
725+ -- allow the deferred things to be definable
726+ -- (this is just to allow users to inspect intermediate
727+ -- things)
728+ <- if (null holes || null def') && not inf
729+ then recheckC_borrowing True (PEGenerated `notElem` opts)
730+ borrowed fc id [] rhs'
731+ else return (rhs', clhsty)
732+
723733 logElab 6 $ " ==> " ++ showEnvDbg [] crhsty ++ " against " ++ showEnvDbg [] clhsty
734+
735+ -- If there's holes, make sure this definition is frozen
736+ when (not (null holes)) $ do
737+ logElab 5 $ "Making " ++ show fname ++ " frozen due to " ++ show holes
738+ setAccessibility fname Frozen
739+
724740 ctxt <- getContext
725741 let constv = next_tvar ctxt
726742 case LState.runStateT (convertsC ctxt [] crhsty clhsty) (constv, []) of
@@ -861,7 +877,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in pn_in withblock)
861877 processTacticDecls info newDecls
862878 sendHighlighting highlights
863879
864− def' <- checkDef fc iderr defer
880+ def' <- checkDef fc iderr True defer
865881 let def'' = map (\(n, (i, top, t, ns)) -> (n, (i, top, t, ns, False, True))) def'
866882 addDeferred def''
867883 mapM_ (elabCaseBlock info opts) is
@@ -926,7 +942,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in pn_in withblock)
926942 addIBC (IBCImp wname)
927943 addIBC (IBCStatic wname)
928944
929− def' <- checkDef fc iderr [(wname, (-1, Nothing, wtype, []))]
945+ def' <- checkDef fc iderr True [(wname, (-1, Nothing, wtype, []))]
930946 let def'' = map (\(n, (i, top, t, ns)) -> (n, (i, top, t, ns, False, True))) def'
931947 addDeferred def''
932948
@@ -967,7 +983,7 @@ elabClause info opts (_, PWith fc fname lhs_in withs wval_in pn_in withblock)
967983 processTacticDecls info newDecls
968984 sendHighlighting highlights
969985
970− def' <- checkDef fc iderr defer
986+ def' <- checkDef fc iderr True defer
971987 let def'' = map (\(n, (i, top, t, ns)) -> (n, (i, top, t, ns, False, True))) def'
972988 addDeferred def''
973989 mapM_ (elabCaseBlock info opts) is