@@ -1028,12 +1028,22 @@ elab ist info emode opts fn tm
1029 elab' ina _ c@(PCase fc scr opts)
1029 elab' ina _ c@(PCase fc scr opts)
1030 = do attack
1030 = do attack
1031 tyn <- getNameFrom (sMN 0 "scty")
1032 tyn <- getNameFrom (sMN 0 "scty")
1032 claim tyn RType
1033 claim tyn RType
1033 valn <- getNameFrom (sMN 0 "scval")
1034 valn <- getNameFrom (sMN 0 "scval")
1034 scvn <- getNameFrom (sMN 0 "scvar")
1035 scvn <- getNameFrom (sMN 0 "scvar")
1035 claim valn (Var tyn)
1036 claim valn (Var tyn)
1036 letbind scvn (Var tyn) (Var valn)
1037 letbind scvn (Var tyn) (Var valn)
1039+ -- Start filling in the scrutinee type, if we can work one
1040+ -- out from the case options
1041+ let scrTy = getScrType (map fst opts)
1043+ Nothing -> return ()
1044+ Just ty -> do focus tyn
1045+ elabE ina (Just fc) ty
1037 focus valn
1047 focus valn
1038 elabE (ina { e_inarg = True }) (Just fc) scr
1048 elabE (ina { e_inarg = True }) (Just fc) scr
1039 -- Solve any remaining implicits - we need to solve as many
1049 -- Solve any remaining implicits - we need to solve as many
@@ -1084,6 +1094,21 @@ elab ist info emode opts fn tm
1084 Just xs@(_:_) -> sNS n xs
1094 Just xs@(_:_) -> sNS n xs
1097+ getScrType [] = Nothing
1098+ getScrType (f : os) = maybe (getScrType os) Just (getAppType f)
1100+ getAppType (PRef _ _ n) =
1101+ case lookupTyName n (tt_ctxt ist) of
1102+ [(n', ty)] | isDConName n' (tt_ctxt ist) ->
1103+ case unApply (getRetTy ty) of
1104+ (P _ tyn _, args) ->
1105+ Just (PApp fc (PRef fc [] tyn)
1106+ (map pexp (map (const Placeholder) args)))
1108+ _ -> Nothing -- ambiguity is no help to us!
1109+ getAppType (PApp _ t as) = getAppType t
1110+ getAppType _ = Nothing
1087 inApp (P _ n _) = [n]
1112 inApp (P _ n _) = [n]
1088 inApp (App _ f a) = inApp f ++ inApp a
1113 inApp (App _ f a) = inApp f ++ inApp a
1089 inApp (Bind n (Let _ v) sc) = inApp v ++ inApp sc
1114 inApp (Bind n (Let _ v) sc) = inApp v ++ inApp sc