@@ -484,7 +484,7 @@ data PTerm = PQuote Raw
484 | PMetavar Name
484 | PMetavar Name
485 | PProof [PTactic]
485 | PProof [PTactic]
486 | PTactics [PTactic] -- as PProof, but no auto solving
486 | PTactics [PTactic] -- as PProof, but no auto solving
487− | PElabError String -- error to report on elaboration
487+ | PElabError Err -- error to report on elaboration
488 | PImpossible -- special case for declaring when an LHS can't typecheck
488 | PImpossible -- special case for declaring when an LHS can't typecheck
489 deriving Eq
489 deriving Eq
@@ -777,7 +777,7 @@ showImp impl tm = se 10 tm where
777 se p PImpossible = "impossible"
777 se p PImpossible = "impossible"
778 se p Placeholder = "_"
778 se p Placeholder = "_"
779 se p (PDoBlock _) = "do block show not implemented"
779 se p (PDoBlock _) = "do block show not implemented"
780− se p (PElabError s) = s
780+ se p (PElabError s) = show s
781-- se p x = "Not implemented"
781-- se p x = "Not implemented"
783 sArg (PImp _ _ n tm) = siArg (n, tm)
783 sArg (PImp _ _ n tm) = siArg (n, tm)
@@ -1141,9 +1141,9 @@ addImpl' :: Bool -> [Name] -> IState -> PTerm -> PTerm
1141addImpl' inpat env ist ptm = ai env ptm
1141addImpl' inpat env ist ptm = ai env ptm
1143 ai env (PRef fc f)
1143 ai env (PRef fc f)
1144− | not (f `elem` env) = aiFn inpat ist fc f []
1144+ | not (f `elem` env) = handleErr $ aiFn inpat ist fc f []
1145 ai env (PHidden (PRef fc f))
1145 ai env (PHidden (PRef fc f))
1146− | not (f `elem` env) = aiFn False ist fc f []
1146+ | not (f `elem` env) = handleErr $ aiFn False ist fc f []
1147 ai env (PEq fc l r) = let l' = ai env l
1147 ai env (PEq fc l r) = let l' = ai env l
1148 r' = ai env r in
1148 r' = ai env r in
1149 PEq fc l' r'
1149 PEq fc l' r'
@@ -1162,7 +1162,7 @@ addImpl' inpat env ist ptm = ai env ptm
1162 ai env (PApp fc (PRef _ f) as)
1162 ai env (PApp fc (PRef _ f) as)
1163 | not (f `elem` env)
1163 | not (f `elem` env)
1164 = let as' = map (fmap (ai env)) as in
1164 = let as' = map (fmap (ai env)) as in
1165− aiFn False ist fc f as'
1165+ handleErr $ aiFn False ist fc f as'
1166 ai env (PApp fc f as) = let f' = ai env f
1166 ai env (PApp fc f as) = let f' = ai env f
1167 as' = map (fmap (ai env)) as in
1167 as' = map (fmap (ai env)) as in
1168 mkPApp fc 1 f' as'
1168 mkPApp fc 1 f' as'
@@ -1185,30 +1185,34 @@ addImpl' inpat env ist ptm = ai env ptm
1185 ai env (PTactics ts) = PTactics (map (fmap (ai env)) ts)
1185 ai env (PTactics ts) = PTactics (map (fmap (ai env)) ts)
1186 ai env tm = tm
1186 ai env tm = tm
1188+ handleErr (Left err) = PElabError err
1189+ handleErr (Right x) = x
1188-- if in a pattern, and there are no arguments, and there's no possible
1191-- if in a pattern, and there are no arguments, and there's no possible
1189-- names with zero explicit arguments, don't add implicits.
1192-- names with zero explicit arguments, don't add implicits.
1191−aiFn :: Bool -> IState -> FC -> Name -> [PArg] -> PTerm
1194+aiFn :: Bool -> IState -> FC -> Name -> [PArg] -> Either Err PTerm
1192aiFn True ist fc f []
1195aiFn True ist fc f []
1193 = case lookupCtxt Nothing f (idris_implicits ist) of
1196 = case lookupCtxt Nothing f (idris_implicits ist) of
1194− [] -> PRef fc f
1197+ [] -> Right $ PRef fc f
1195 alts -> if (any (all imp) alts)
1198 alts -> if (any (all imp) alts)
1196 then aiFn False ist fc f [] -- use it as a constructor
1199 then aiFn False ist fc f [] -- use it as a constructor
1197− else PRef fc f
1200+ else Right $ PRef fc f
1198 where imp (PExp _ _ _) = False
1201 where imp (PExp _ _ _) = False
1199 imp _ = True
1202 imp _ = True
1200aiFn inpat ist fc f as
1203aiFn inpat ist fc f as
1201− | f `elem` primNames = PApp fc (PRef fc f) as
1204+ | f `elem` primNames = Right $ PApp fc (PRef fc f) as
1202aiFn inpat ist fc f as
1205aiFn inpat ist fc f as
1203 -- This is where namespaces get resolved by adding PAlternative
1206 -- This is where namespaces get resolved by adding PAlternative
1204 = case lookupCtxtName Nothing f (idris_implicits ist) of
1207 = case lookupCtxtName Nothing f (idris_implicits ist) of
1205− [(f',ns)] -> mkPApp fc (length ns) (PRef fc f') (insertImpl ns as)
1208+ [(f',ns)] -> Right $ mkPApp fc (length ns) (PRef fc f') (insertImpl ns as)
1206 [] -> if f `elem` idris_metavars ist
1209 [] -> if f `elem` idris_metavars ist
1207− then PApp fc (PRef fc f) as
1210+ then Right $ PApp fc (PRef fc f) as
1208− else mkPApp fc (length as) (PRef fc f) as
1211+ else Right $ mkPApp fc (length as) (PRef fc f) as
1209− alts -> PAlternative $
1213+ PAlternative $
1210− map (\(f', ns) -> mkPApp fc (length ns) (PRef fc f')
1214+ map (\(f', ns) -> mkPApp fc (length ns) (PRef fc f')
1211− (insertImpl ns as)) alts
1215+ (insertImpl ns as)) alts
1213 insertImpl :: [PArg] -> [PArg] -> [PArg]
1217 insertImpl :: [PArg] -> [PArg] -> [PArg]
1214 insertImpl (PExp p l ty : ps) (PExp _ _ tm : given) =
1218 insertImpl (PExp p l ty : ps) (PExp _ _ tm : given) =