Skip to content

Commit

Permalink
4.3.0 compat, plus better errors
Browse files Browse the repository at this point in the history
  • Loading branch information
david-christiansen committed Aug 9, 2024
1 parent 6fe920e commit ebb969f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/compat/SubVerso/Compat.lean
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ def realizeNameNoOverloads


elab "%first_succeeding" "[" es:term,* "]" : term <= ty => do
let mut errs := #[]
for e in es.getElems do
try
let expr ←
withReader ({· with errToSorry := false}) <|
elabTerm e (some ty)
return expr
catch _ =>
elabTermEnsuringType e (some ty)
let ty' ← Meta.inferType expr
if ← Meta.isDefEq ty ty' then
return expr
catch err =>
errs := errs.push (e, err)
continue
throwError "No alternative succeeded"
let msgErrs := errs.toList.map fun (tm, msg) => m!"{tm}: {indentD msg.toMessageData}"
throwError m!"No alternative succeeded. Attempts were: " ++
indentD (MessageData.joinSep msgErrs Format.line)

open Command in
elab "%if_bound" x:ident cmd:command : command => do
Expand Down Expand Up @@ -83,7 +89,7 @@ instance [BEq α] [Hashable α] {x : α} {hm : HashMap α β} : Decidable (x ∈

instance instGetElemHashMap [BEq α] [Hashable α] [Inhabited β] : GetElem (HashMap α β) α β (fun m a => a ∈ m) :=
%first_succeeding [
inferInstanceAs (GetElem (Std.HashMap α β) α β (fun m a => a ∈ m))--,
inferInstanceAs (GetElem (Std.HashMap α β) α β (fun m a => a ∈ m)),
fun m a _ok => m.find! a⟩,
fun m a _ok => m.find! a, fun m a => Lean.HashMap.find? m a, fun m a => Lean.HashMap.find! m a⟩
]
Expand Down

0 comments on commit ebb969f

Please sign in to comment.