@@ -94,7 +94,7 @@ build ist info emode opts fn tm
9494 when tydecl (do update_term orderPats
9595 mkPat)
9696-- update_term liftPats)
97− is <- getAux
97+ EState is _ <- getAux
9898 tt <- get_term
9999 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
100100 log <- getLog
@@ -130,7 +130,12 @@ buildTC ist info emode opts fn tm
130130 [] -> return ()
131131 ((_,_,_,_,e,_,_):es) -> if inf then return ()
132132 else lift (Error e)
133− is <- getAux
133+ dots <- get_dotterm
134+ -- 'dots' are the PHidden things which have not been solved by
135+ -- unification
136+ when (not (null dots)) $
137+ lift (Error (CantMatch (getInferTerm tm)))
138+ EState is _ <- getAux
134139 tt <- get_term
135140 let (tm, ds) = runState (collectDeferred (Just fn) tt) []
136141 log <- getLog
@@ -181,6 +186,8 @@ elab ist info emode opts fn tm
181186 compute -- expand type synonyms, etc
182187 let fc = maybe "(unknown)"
183188 elabE initElabCtxt (elabFC info) tm -- (in argument, guarded, in type, in qquote)
189+ est <- getAux
190+ sequence_ (delayed_elab est)
184191 end_unify
185192 ptm <- get_term
186193 when pattern -- convert remaining holes to pattern vars
@@ -388,7 +395,7 @@ elab ist info emode opts fn tm
388395 trySeq' deferr (x : xs)
389396 = try' (do elab' ina fc x
390397 solveAutos ist fn False) (trySeq' deferr xs) True
391− elab' ina _ (PPatvar fc n) | bindfree = do patvar n; -- update_term liftPats
398+ elab' ina _ (PPatvar fc n) | bindfree = do patvar n; update_term liftPats
392399-- elab' (_, _, inty) (PRef fc f)
393400-- | isTConName f (tt_ctxt ist) && pattern && not reflection && not inty
394401-- = lift $ tfail (Msg "Typecase is not allowed")
@@ -587,9 +594,13 @@ elab ist info emode opts fn tm
587594 | otherwise
588595 = do env <- get_env
589596 ty <- goal
597+ ctxt <- get_context
590598 let unmatchableArgs = if pattern
591599 then getUnmatchable (tt_ctxt ist) f
592600 else []
601+ -- Dot it if we're in a pattern and it isn't a constructor
602+-- when (pattern && not (isDConName f ctxt) && f /= fn) $ dotterm
603+
593604 when (pattern && not reflection && not (e_qq ina) && not (e_intype ina)
594605 && isTConName f (tt_ctxt ist)) $
595606 lift $ tfail $ Msg ("No explicit types on left hand side: " ++ show tm)
@@ -612,7 +623,6 @@ elab ist info emode opts fn tm
612623 _ -> do mapM_ setInjective (map getTm args)
613624 -- maybe more things are solvable now
614625 unifyProblems
615− ctxt <- get_context
616626 let guarded = isConName f ctxt
617627-- trace ("args is " ++ show args) $ return ()
618628 ns <- apply (Var f) (map isph args)
@@ -666,13 +676,15 @@ elab ist info emode opts fn tm
666676 PLam _ _ _ -> 3
667677 PRewrite _ _ _ _ -> 4
668678 PResolveTC _ -> 0
679+ PHidden _ -> 150
669680 _ -> 1
670681
671682 constraint (PConstraint _ _ _ _) = True
672683 constraint _ = False
673684
674685 -- Score a point for every level where there is a non-constructor
675− -- function (so higher score --> done later)
686+ -- function (so higher score --> done later), and lots of points
687+ -- if there is a PHidden since this should be unifiable.
676688 -- Only relevant when on lhs
677689 conDepth d t | not pattern = 0
678690 conDepth d (PRef _ f) | isConName f (tt_ctxt ist) = 0
@@ -681,6 +693,7 @@ elab ist info emode opts fn tm
681693 = conDepth d f + sum (map (conDepth (d+1)) (map getTm as))
682694 conDepth d (PPatvar _ _) = 0
683695 conDepth d (PAlternative _ as) = maximum (map (conDepth d) as)
696+ conDepth d (PHidden _) = 150
684697 conDepth d Placeholder = 0
685698 conDepth d (PResolveTC _) = 0
686699 conDepth d t = max (100 - d) 1
@@ -810,7 +823,7 @@ elab ist info emode opts fn tm
810823 (caseBlock fc cname'
811824 (map (isScr scr) (reverse args')) opts)
812825 -- elaborate case
813− updateAux (newdef : )
826+ updateAux (\e -> e { case_decls = newdef : case_decls e } )
814827 -- if we haven't got the type yet, hopefully we'll get it later!
815828 movelast tyn
816829 solve
@@ -930,8 +943,24 @@ elab ist info emode opts fn tm
930943
931944 elab' ina fc (PUnquote t) = fail "Found unquote outside of quasiquote"
932945 elab' ina fc (PAs _ n t) = lift . tfail . Msg $ "@-pattern not allowed here"
946+ elab' ina fc (PHidden t)
947+ | reflection = elab' ina fc t
948+ | otherwise
949+ = do (h : hs) <- get_holes
950+ -- Dotting a hole means that either the hole or any outer
951+ -- hole (a hole outside any occurrence of it)
952+ -- must be solvable by unification as well as being filled
953+ -- in directly.
954+ -- Delay dotted things to the end, then when we elaborate them
955+ -- we can check the result against what was inferred
956+ movelast h
957+ delayElab $ do focus h
958+ dotterm
959+ elab' ina fc t
933960 elab' ina fc x = fail $ "Unelaboratable syntactic form " ++ showTmImpls x
934961
962+ delayElab t = updateAux (\e -> e { delayed_elab = delayed_elab e ++ [t] })
963+
935964 isScr :: PTerm -> (Name, Binder Term) -> (Name, (Bool, Binder Term))
936965 isScr (PRef _ n) (n', b) = (n', (n == n', b))
937966 isScr _ (n', b) = (n', (False, b))
@@ -1126,6 +1155,7 @@ pruneByType env t c as
11261155 | otherwise = locallyBound ts
11271156 getName (PRef _ n) = Just n
11281157 getName (PApp _ f _) = getName f
1158+ getName (PHidden t) = getName t
11291159 getName _ = Nothing
11301160
11311161pruneByType env (P _ n _) ctxt as
@@ -1143,6 +1173,7 @@ pruneByType env (P _ n _) ctxt as
11431173 headIs var f (PApp _ (PRef _ f') _) = typeHead var f f'
11441174 headIs var f (PApp _ f' _) = headIs var f f'
11451175 headIs var f (PPi _ _ _ sc) = headIs var f sc
1176+ headIs var f (PHidden t) = headIs var f t
11461177 headIs _ _ _ = True -- keep if it's not an application
11471178
11481179 typeHead var f f'
@@ -2195,6 +2226,7 @@ reflectErr (TooManyArguments n) = raw_apply (Var $ reflErrName "TooManyArguments
21952226reflectErr (CantIntroduce t) = raw_apply (Var $ reflErrName "CantIntroduce") [reflect t]
21962227reflectErr (NoSuchVariable n) = raw_apply (Var $ reflErrName "NoSuchVariable") [reflectName n]
21972228reflectErr (WithFnType t) = raw_apply (Var $ reflErrName "WithFnType") [reflect t]
2229+reflectErr (CantMatch t) = raw_apply (Var $ reflErrName "CantMatch") [reflect t]
21982230reflectErr (NoTypeDecl n) = raw_apply (Var $ reflErrName "NoTypeDecl") [reflectName n]
21992231reflectErr (NotInjective t1 t2 t3) =
22002232 raw_apply (Var $ reflErrName "NotInjective")
@@ -2306,7 +2338,7 @@ reifyReportPart (App (P (DCon _ _ _) n _) (Constant (Str msg))) | n == reflm "Te
23062338 Right (TextPart msg)
23072339reifyReportPart (App (P (DCon _ _ _) n _) ttn)
23082340 | n == reflm "NamePart" =
2309− case runElab [] (reifyTTName ttn) (initElaborator NErased initContext Erased) of
2341+ case runElab initEState (reifyTTName ttn) (initElaborator NErased initContext Erased) of
23102342 Error e -> Left . InternalMsg $
23112343 "could not reify name term " ++
23122344 show ttn ++
@@ -2314,7 +2346,7 @@ reifyReportPart (App (P (DCon _ _ _) n _) ttn)
23142346 OK (n', _)-> Right $ NamePart n'
23152347reifyReportPart (App (P (DCon _ _ _) n _) tm)
23162348 | n == reflm "TermPart" =
2317− case runElab [] (reifyTT tm) (initElaborator NErased initContext Erased) of
2349+ case runElab initEState (reifyTT tm) (initElaborator NErased initContext Erased) of
23182350 Error e -> Left . InternalMsg $
23192351 "could not reify reflected term " ++
23202352 show tm ++