@@ -8,6 +8,7 @@ module Idris.Delaborate where
88import Idris.AbsSyntax
99import Idris.Core.TT
1010import Idris.Core.Evaluate
11+import Idris.ErrReverse
1112
1213import Data.List (intersperse)
1314
@@ -121,11 +122,13 @@ indented text = boxIt '\n' $ unlines $ map ('\t':) $ lines text where
121122 else [c]
122123
123124pshow :: IState -> Err -> String
124−pshow i (Msg s) = s
125−pshow i (InternalMsg s) = "INTERNAL ERROR: " ++ show s ++
125+pshow i err = pshow' i (fmap (errReverse i) err)
126+
127+pshow' i (Msg s) = s
128+pshow' i (InternalMsg s) = "INTERNAL ERROR: " ++ show s ++
126129 "\nThis is probably a bug, or a missing error message.\n" ++
127130 "Please consider reporting at " ++ bugaddr
128−pshow i (CantUnify _ x y e sc s)
131+pshow' i (CantUnify _ x y e sc s)
129132 = let imps = opt_showimp (idris_options i) in
130133 let colour = idris_colourRepl i in
131134 "Can't unify" ++ indented (showImp (Just i) imps colour (delab i x))
@@ -134,72 +137,72 @@ pshow i (CantUnify _ x y e sc s)
134137 case e of
135138 Msg "" -> ""
136139 _ -> "\nSpecifically:" ++
137− indented (pshow i e) ++
140+ indented (pshow' i e) ++
138141 if (opt_errContext (idris_options i)) then showSc i sc else ""
139−pshow i (CantConvert x y env)
142+pshow' i (CantConvert x y env)
140143 = let imps = opt_showimp (idris_options i) in
141144 let colour = idris_colourRepl i in
142145 "Can't convert" ++ indented (showImp (Just i) imps colour (delab i x)) ++ "with"
143146 ++ indented (showImp (Just i) imps colour (delab i y)) ++
144147 if (opt_errContext (idris_options i)) then showSc i env else ""
145−pshow i (CantSolveGoal x env)
148+pshow' i (CantSolveGoal x env)
146149 = let imps = opt_showimp (idris_options i) in
147150 let colour = idris_colourRepl i in
148151 "Can't solve goal " ++ indented (showImp (Just i) imps colour (delab i x)) ++
149152 if (opt_errContext (idris_options i)) then showSc i env else ""
150−pshow i (UnifyScope n out tm env)
153+pshow' i (UnifyScope n out tm env)
151154 = let imps = opt_showimp (idris_options i) in
152155 let colour = idris_colourRepl i in
153156 "Can't unify" ++ indented (show n) ++ "with"
154157 ++ indented (showImp (Just i) imps colour (delab i tm)) ++ "as" ++
155158 indented (show out) ++ "is not in scope" ++
156159 if (opt_errContext (idris_options i)) then showSc i env else ""
157−pshow i (CantInferType t)
160+pshow' i (CantInferType t)
158161 = "Can't infer type for " ++ t
159−pshow i (NonFunctionType f ty)
162+pshow' i (NonFunctionType f ty)
160163 = let imps = opt_showimp (idris_options i) in
161164 let colour = idris_colourRepl i in
162165 showImp (Just i) imps colour (delab i f) ++ " does not have a function type ("
163166 ++ showImp (Just i) imps colour (delab i ty) ++ ")"
164−pshow i (NotEquality tm ty)
167+pshow' i (NotEquality tm ty)
165168 = let imps = opt_showimp (idris_options i) in
166169 let colour = idris_colourRepl i in
167170 showImp (Just i) imps colour (delab i tm) ++ " does not have an equality type ("
168171 ++ showImp (Just i) imps colour (delab i ty) ++ ")"
169−pshow i (TooManyArguments f)
172+pshow' i (TooManyArguments f)
170173 = "Too many arguments for " ++ show f
171−pshow i (CantIntroduce ty)
174+pshow' i (CantIntroduce ty)
172175 = let imps = opt_showimp (idris_options i) in
173176 let colour = idris_colourRepl i in
174177 "Can't use lambda here: type is " ++ showImp (Just i) imps colour (delab i ty)
175−pshow i (InfiniteUnify x tm env)
178+pshow' i (InfiniteUnify x tm env)
176179 = "Unifying " ++ showbasic x ++ " and " ++ show (delab i tm) ++
177180 " would lead to infinite value" ++
178181 if (opt_errContext (idris_options i)) then showSc i env else ""
179−pshow i (NotInjective p x y) = "Can't verify injectivity of " ++ show (delab i p) ++
180− " when unifying " ++ show (delab i x) ++ " and " ++
181− show (delab i y)
182−pshow i (CantResolve c) = "Can't resolve type class " ++ show (delab i c)
183−pshow i (CantResolveAlts as) = "Can't disambiguate name: " ++ showSep ", " as
184−pshow i (NoTypeDecl n) = "No type declaration for " ++ show n
185−pshow i (NoSuchVariable n) = "No such variable " ++ show n
186−pshow i (IncompleteTerm t) = "Incomplete term " ++ showImp Nothing True False (delab i t)
187−pshow i UniverseError = "Universe inconsistency"
188−pshow i ProgramLineComment = "Program line next to comment"
189−pshow i (Inaccessible n) = show n ++ " is not an accessible pattern variable"
190−pshow i (NonCollapsiblePostulate n)
182+pshow' i (NotInjective p x y) = "Can't verify injectivity of " ++ show (delab i p) ++
183+ " when unifying " ++ show (delab i x) ++ " and " ++
184+ show (delab i y)
185+pshow' i (CantResolve c) = "Can't resolve type class " ++ show (delab i c)
186+pshow' i (CantResolveAlts as) = "Can't disambiguate name: " ++ showSep ", " as
187+pshow' i (NoTypeDecl n) = "No type declaration for " ++ show n
188+pshow' i (NoSuchVariable n) = "No such variable " ++ show n
189+pshow' i (IncompleteTerm t) = "Incomplete term " ++ showImp Nothing True False (delab i t)
190+pshow' i UniverseError = "Universe inconsistency"
191+pshow' i ProgramLineComment = "Program line next to comment"
192+pshow' i (Inaccessible n) = show n ++ " is not an accessible pattern variable"
193+pshow' i (NonCollapsiblePostulate n)
191194 = "The return type of postulate " ++ show n ++ " is not collapsible"
192−pshow i (AlreadyDefined n) = show n ++ " is already defined"
193−pshow i (ProofSearchFail e) = pshow i e
194−pshow i (NoRewriting tm) = "rewrite did not change type " ++ show (delab i tm)
195−pshow i (At f e) = show f ++ ":" ++ pshow i e
196−pshow i (Elaborating s n e) = "When elaborating " ++ s ++
197− showqual i n ++ ":\n" ++ pshow i e
198−pshow i (ProviderError msg) = "Type provider error: " ++ msg
199−pshow i (LoadingFailed fn e) = "Loading " ++ fn ++ " failed: " ++ pshow i e
200−pshow i (ReflectionError parts orig) = let parts' = map (concat . intersperse " " . map showPart) parts in
195+pshow' i (AlreadyDefined n) = show n ++ " is already defined"
196+pshow' i (ProofSearchFail e) = pshow' i e
197+pshow' i (NoRewriting tm) = "rewrite did not change type " ++ show (delab i tm)
198+pshow' i (At f e) = show f ++ ":" ++ pshow' i e
199+pshow' i (Elaborating s n e) = "When elaborating " ++ s ++
200+ showqual i n ++ ":\n" ++ pshow' i e
201+pshow' i (ProviderError msg) = "Type provider error: " ++ msg
202+pshow' i (LoadingFailed fn e) = "Loading " ++ fn ++ " failed: " ++ pshow' i e
203+pshow' i (ReflectionError parts orig) = let parts' = map (concat . intersperse " " . map showPart) parts in
201204 concat (intersperse "\n" parts') ++
202− "\nOriginal error:\n" ++ indented (pshow i orig)
205+ "\nOriginal error:\n" ++ indented (pshow' i orig)
203206 where showPart :: ErrorReportPart -> String
204207 showPart (TextPart str) = str
205208 showPart (NamePart n) = let colour = idris_colourRepl i in
@@ -207,8 +210,8 @@ pshow i (ReflectionError parts orig) = let parts' = map (concat . intersperse "
207210 showPart (TermPart tm) = let colour = idris_colourRepl i
208211 in showImp (Just i) False colour (delab i tm)
209212 showPart (SubReport rs) = indented . concat . intersperse " " . map showPart $ rs
210−pshow i (ReflectionFailed msg err) = "When attempting to perform error reflection, the following internal error occurred:\n" ++
211− indented (pshow i err) ++
213+pshow' i (ReflectionFailed msg err) = "When attempting to perform error reflection, the following internal error occurred:\n" ++
214+ indented (pshow' i err) ++
212215 "\nThis is probably a bug. Please consider reporting it at " ++ bugaddr
213216
214217