@@ -7,6 +7,7 @@ import Idris.Error
7import Idris.Delaborate
7import Idris.Delaborate
8import Idris.Imports
8import Idris.Imports
9import Idris.ElabTerm
9import Idris.ElabTerm
10import Paths_idris
11import Paths_idris
12import Core.TT
13import Core.TT
@@ -18,6 +19,7 @@ import Core.CaseTree
18import Control.Monad
19import Control.Monad
19import Control.Monad.State
20import Control.Monad.State
20import Data.List
21import Data.List
21import Debug.Trace
23import Debug.Trace
@@ -85,9 +87,11 @@ elabCon info syn (n, t_in, fc)
85 return (n, cty)
87 return (n, cty)
87elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
89elabClauses :: ElabInfo -> FC -> FnOpts -> Name -> [PClause] -> Idris ()
88−elabClauses info fc opts n_in cs = let n = liftname info n_in in
90+elabClauses info fc opts n_in cs_in = let n = liftname info n_in in
91+ do let cs = genClauses cs_in
89− do solveDeferred n
92+ solveDeferred n
90− pats <- mapM (elabClause info fc) cs
93+ pats_in <- mapM (elabClause info fc) cs
94+ let pats = mapMaybe id pats_in
91 logLvl 3 (showSep "\n" (map (\ (l,r) ->
95 logLvl 3 (showSep "\n" (map (\ (l,r) ->
92 show l ++ " = " ++
96 show l ++ " = " ++
93 show r) pats))
97 show r) pats))
@@ -127,7 +131,17 @@ elabVal info aspat tm_in
127 logLvl 2 (show vtm)
131 logLvl 2 (show vtm)
128 recheckC ctxt (FC "prompt" 0) [] vtm
132 recheckC ctxt (FC "prompt" 0) [] vtm
130−elabClause :: ElabInfo -> FC -> PClause -> Idris (Term, Term)
134+elabClause :: ElabInfo -> FC -> PClause -> Idris (Maybe (Term, Term))
135+elabClause info fc (PClause fname lhs_in [] PImpossible [])
136+ = do ctxt <- getContext
138+ let lhs = addImpl i lhs_in
139+ -- if the LHS type checks, it is possible, so report an error
140+ case elaborate ctxt (MN 0 "patLHS") infP
141+ (erun fc (build i info True (infTerm lhs))) of
142+ OK _ -> fail $ show fc ++ ":" ++ show lhs ++ " is a possible case"
143+ Error _ -> return ()
131elabClause info fc (PClause fname lhs_in withs rhs_in whereblock)
145elabClause info fc (PClause fname lhs_in withs rhs_in whereblock)
132 = do ctxt <- getContext
146 = do ctxt <- getContext
133 -- Build the LHS as an "Infer", and pull out its type and
147 -- Build the LHS as an "Infer", and pull out its type and
@@ -171,7 +185,7 @@ elabClause info fc (PClause fname lhs_in withs rhs_in whereblock)
171 addDeferred def'
185 addDeferred def'
172 ctxt <- getContext
186 ctxt <- getContext
173 (crhs, crhsty) <- recheckC ctxt fc [] rhs'
187 (crhs, crhsty) <- recheckC ctxt fc [] rhs'
174− return (clhs, crhs)
188+ return $ Just (clhs, crhs)
176 decorate x = UN (show fname ++ "#" ++ show x)
190 decorate x = UN (show fname ++ "#" ++ show x)
177 pinfo ns ps i
191 pinfo ns ps i
@@ -253,7 +267,7 @@ elabClause info fc (PWith fname lhs_in withs wval_in withblock)
253 def' <- checkDef fc defer
267 def' <- checkDef fc defer
254 addDeferred def'
268 addDeferred def'
255 (crhs, crhsty) <- recheckC ctxt fc [] rhs'
269 (crhs, crhsty) <- recheckC ctxt fc [] rhs'
256− return (clhs, crhs)
270+ return $ Just (clhs, crhs)
258 getImps (Bind n (Pi _) t) = pexp Placeholder : getImps t
272 getImps (Bind n (Pi _) t) = pexp Placeholder : getImps t
259 getImps _ = []
273 getImps _ = []
@@ -364,7 +378,7 @@ elabClass info syn fc constraints tn ps ds
364 iLOG (showImp True ty)
378 iLOG (showImp True ty)
365 iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
379 iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
366 return [PTy syn fc cfn ty,
380 return [PTy syn fc cfn ty,
367− PClauses fc True cfn [PClause cfn lhs [] rhs []]]
381+ PClauses fc [Inlinable] cfn [PClause cfn lhs [] rhs []]]
369 tfun cn c syn all (m, ty)
383 tfun cn c syn all (m, ty)
370 = do let ty' = insertConstraint c ty
384 = do let ty' = insertConstraint c ty
@@ -378,7 +392,7 @@ elabClass info syn fc constraints tn ps ds
378 iLOG (show (m, ty', capp, margs))
392 iLOG (show (m, ty', capp, margs))
379 iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
393 iLOG (showImp True lhs ++ " = " ++ showImp True rhs)
380 return [PTy syn fc m ty',
394 return [PTy syn fc m ty',
381− PClauses fc True m [PClause m lhs [] rhs []]]
395+ PClauses fc [Inlinable] m [PClause m lhs [] rhs []]]
383 getMArgs (PPi (Imp _ _) n ty sc) = IA : getMArgs sc
397 getMArgs (PPi (Imp _ _) n ty sc) = IA : getMArgs sc
384 getMArgs (PPi (Exp _ _) n ty sc) = EA : getMArgs sc
398 getMArgs (PPi (Exp _ _) n ty sc) = EA : getMArgs sc
@@ -434,7 +448,7 @@ elabInstance info syn fc cs n ps t ds
434 let lhs = PRef fc iname
448 let lhs = PRef fc iname
435 let rhs = PApp fc (PRef fc (instanceName ci))
449 let rhs = PApp fc (PRef fc (instanceName ci))
436 (map (pexp . mkMethApp) mtys)
450 (map (pexp . mkMethApp) mtys)
437− let idecl = PClauses fc True iname [PClause iname lhs [] rhs wb]
451+ let idecl = PClauses fc [Inlinable] iname [PClause iname lhs [] rhs wb]
438 iLOG (show idecl)
452 iLOG (show idecl)
439 elabDecl info idecl
453 elabDecl info idecl
@@ -472,7 +486,7 @@ elabInstance info syn fc cs n ps t ds
473 insertDef meth def ns decls
487 insertDef meth def ns decls
474 | null $ filter (clauseFor meth ns) decls
488 | null $ filter (clauseFor meth ns) decls
475− = decls ++ [PClauses fc True meth
489+ = decls ++ [PClauses fc [Inlinable] meth
476 [PClause meth (PApp fc (PRef fc meth) []) []
490 [PClause meth (PApp fc (PRef fc meth) []) []
477 (PApp fc (PRef fc def) []) []]]
491 (PApp fc (PRef fc def) []) []]]
478 | otherwise = decls
492 | otherwise = decls