@@ -484,7 +484,7 @@ data PTerm = PQuote Raw
484484 | PMetavar Name
485485 | PProof [PTactic]
486486 | PTactics [PTactic] -- as PProof, but no auto solving
487− | PElabError String -- error to report on elaboration
487+ | PElabError Err -- error to report on elaboration
488488 | PImpossible -- special case for declaring when an LHS can't typecheck
489489 deriving Eq
490490{-!
@@ -777,7 +777,7 @@ showImp impl tm = se 10 tm where
777777 se p PImpossible = "impossible"
778778 se p Placeholder = "_"
779779 se p (PDoBlock _) = "do block show not implemented"
780− se p (PElabError s) = s
780+ se p (PElabError s) = show s
781781-- se p x = "Not implemented"
782782
783783 sArg (PImp _ _ n tm) = siArg (n, tm)
@@ -1141,9 +1141,9 @@ addImpl' :: Bool -> [Name] -> IState -> PTerm -> PTerm
11411141addImpl' inpat env ist ptm = ai env ptm
11421142 where
11431143 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 []
11451145 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 []
11471147 ai env (PEq fc l r) = let l' = ai env l
11481148 r' = ai env r in
11491149 PEq fc l' r'
@@ -1162,7 +1162,7 @@ addImpl' inpat env ist ptm = ai env ptm
11621162 ai env (PApp fc (PRef _ f) as)
11631163 | not (f `elem` env)
11641164 = let as' = map (fmap (ai env)) as in
1165− aiFn False ist fc f as'
1165+ handleErr $ aiFn False ist fc f as'
11661166 ai env (PApp fc f as) = let f' = ai env f
11671167 as' = map (fmap (ai env)) as in
11681168 mkPApp fc 1 f' as'
@@ -1185,30 +1185,34 @@ addImpl' inpat env ist ptm = ai env ptm
11851185 ai env (PTactics ts) = PTactics (map (fmap (ai env)) ts)
11861186 ai env tm = tm
11871187
1188+ handleErr (Left err) = PElabError err
1189+ handleErr (Right x) = x
1190+
11881191-- if in a pattern, and there are no arguments, and there's no possible
11891192-- names with zero explicit arguments, don't add implicits.
11901193
1191−aiFn :: Bool -> IState -> FC -> Name -> [PArg] -> PTerm
1194+aiFn :: Bool -> IState -> FC -> Name -> [PArg] -> Either Err PTerm
11921195aiFn True ist fc f []
11931196 = case lookupCtxt Nothing f (idris_implicits ist) of
1194− [] -> PRef fc f
1197+ [] -> Right $ PRef fc f
11951198 alts -> if (any (all imp) alts)
11961199 then aiFn False ist fc f [] -- use it as a constructor
1197− else PRef fc f
1200+ else Right $ PRef fc f
11981201 where imp (PExp _ _ _) = False
11991202 imp _ = True
12001203aiFn 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
12021205aiFn inpat ist fc f as
12031206 -- This is where namespaces get resolved by adding PAlternative
12041207 = 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)
12061209 [] -> if f `elem` idris_metavars ist
1207− then PApp fc (PRef fc f) as
1208− else mkPApp fc (length as) (PRef fc f) as
1209− alts -> PAlternative $
1210− map (\(f', ns) -> mkPApp fc (length ns) (PRef fc f')
1211− (insertImpl ns as)) alts
1210+ then Right $ PApp fc (PRef fc f) as
1211+ else Right $ mkPApp fc (length as) (PRef fc f) as
1212+ alts -> Right $
1213+ PAlternative $
1214+ map (\(f', ns) -> mkPApp fc (length ns) (PRef fc f')
1215+ (insertImpl ns as)) alts
12121216 where
12131217 insertImpl :: [PArg] -> [PArg] -> [PArg]
12141218 insertImpl (PExp p l ty : ps) (PExp _ _ tm : given) =