@@ -28,6 +28,7 @@ import qualified Util.Pretty as U
2828import Control.Applicative ((<$>))
2929import Control.Monad
3030import Control.Monad.State.Strict
31+import Data.Foldable (for_)
3132import Data.List
3233import qualified Data.Map as M
3334import Data.Maybe (mapMaybe, fromMaybe, catMaybes)
@@ -1245,6 +1246,7 @@ elab ist info emode opts fn tm
12451246 attack -- to get an extra hole
12461247 elab' ina (Just fc') tm
12471248 script <- get_guess
1249+ fullyElaborated script
12481250 solve -- eliminate the hole. Becuase there are no references, the script is only in the binding
12491251 env <- get_env
12501252 runElabAction ist (maybe fc' id fc) env script ns
@@ -1360,6 +1362,19 @@ elab ist info emode opts fn tm
13601362 getFC d (PAlternative _ _ (x:_)) = getFC d x
13611363 getFC d x = d
13621364
1365+ -- Fail if a term is not yet fully elaborated (e.g. if it contains
1366+ -- case block functions that don't yet exist)
1367+ fullyElaborated :: Term -> ElabD ()
1368+ fullyElaborated (P _ n _) =
1369+ do EState cases _ _ _ <- getAux
1370+ case lookup n cases of
1371+ Nothing -> return ()
1372+ Just _ -> lift . tfail $ ElabScriptStaging n
1373+ fullyElaborated (Bind n b body) = fullyElaborated body >> for_ b fullyElaborated
1374+ fullyElaborated (App _ l r) = fullyElaborated l >> fullyElaborated r
1375+ fullyElaborated (Proj t _) = fullyElaborated t
1376+ fullyElaborated _ = return ()
1377+
13631378 insertLazy :: PTerm -> ElabD PTerm
13641379 insertLazy t@(PApp _ (PRef _ _ (UN l)) _) | l == txt "Delay" = return t
13651380 insertLazy t@(PApp _ (PRef _ _ (UN l)) _) | l == txt "Force" = return t