Skip to content

Commit c339827

Browse files
buzdengallais
authored andcommitted
[ elab ] Add an ability to fail elab script with a custom FC
1 parent 377b21e commit c339827

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

libs/base/Language/Reflection.idr

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export
1212
data Elab : Type -> Type where
1313
Pure : a -> Elab a
1414
Bind : Elab a -> (a -> Elab b) -> Elab b
15-
Fail : String -> Elab a
15+
Fail : FC -> String -> Elab a
1616

1717
LogMsg : String -> Nat -> String -> Elab ()
1818
LogTerm : String -> Nat -> String -> TTImp -> Elab ()
@@ -63,7 +63,11 @@ Monad Elab where
6363
||| Report an error in elaboration
6464
export
6565
fail : String -> Elab a
66-
fail = Fail
66+
fail = Fail EmptyFC
67+
68+
export
69+
failAt : FC -> String -> Elab a
70+
failAt = Fail
6771

6872
||| Write a log message, if the log level is >= the given level
6973
export

src/TTImp/Elab/RunElab.idr

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,12 @@ elabScript fc nest env script@(NDCon nfc nm t ar args) exp
6363
!(sc defs (toClosure withAll env
6464
!(quote defs env act'))) exp
6565
x => failWith defs $ "non-function RHS of a Bind: " ++ show x
66-
elabCon defs "Fail" [_,msg]
66+
elabCon defs "Fail" [_, mbfc, msg]
6767
= do msg' <- evalClosure defs msg
68-
throw (GenericMsg fc ("Error during reflection: " ++
68+
let customFC = case !(evalClosure defs mbfc >>= reify defs) of
69+
EmptyFC => fc
70+
x => x
71+
throw (GenericMsg customFC ("Error during reflection: " ++
6972
!(reify defs msg')))
7073
elabCon defs "LogMsg" [topic, verb, str]
7174
= do topic' <- evalClosure defs topic

0 commit comments

Comments
 (0)