feat: improve split tactic error message
This commit is contained in:
parent
902e60c480
commit
c491659970
3 changed files with 18 additions and 4 deletions
|
|
@ -20,12 +20,12 @@ open Meta
|
|||
throwErrorAt stx[2] "'split' tactic failed, select a single target to split"
|
||||
if simplifyTarget then
|
||||
liftMetaTactic fun mvarId => do
|
||||
let some mvarIds ← splitTarget? mvarId | throwError "'split' tactic failed"
|
||||
let some mvarIds ← splitTarget? mvarId | Meta.throwTacticEx `split mvarId ""
|
||||
return mvarIds
|
||||
else
|
||||
let fvarId ← getFVarId hyps[0]
|
||||
liftMetaTactic fun mvarId => do
|
||||
let some mvarIds ← splitLocalDecl? mvarId fvarId | throwError "'split' tactic failed"
|
||||
let some mvarIds ← splitLocalDecl? mvarId fvarId | Meta.throwTacticEx `split mvarId ""
|
||||
return mvarIds
|
||||
| Location.wildcard =>
|
||||
liftMetaTactic fun mvarId => do
|
||||
|
|
@ -33,7 +33,7 @@ open Meta
|
|||
for fvarId in fvarIds do
|
||||
if let some mvarIds ← splitLocalDecl? mvarId fvarId then
|
||||
return mvarIds
|
||||
let some mvarIds ← splitTarget? mvarId | throwError "'split' tactic failed"
|
||||
let some mvarIds ← splitTarget? mvarId | Meta.throwTacticEx `split mvarId ""
|
||||
return mvarIds
|
||||
|
||||
end Lean.Elab.Tactic
|
||||
|
|
|
|||
|
|
@ -59,6 +59,17 @@ inductive MessageData where
|
|||
|
||||
namespace MessageData
|
||||
|
||||
partial def isEmpty : MessageData → Bool
|
||||
| ofFormat f => f.isEmpty
|
||||
| withContext _ m => m.isEmpty
|
||||
| withNamingContext _ m => m.isEmpty
|
||||
| nest _ m => m.isEmpty
|
||||
| group m => m.isEmpty
|
||||
| compose m₁ m₂ => m₁.isEmpty && m₂.isEmpty
|
||||
| tagged _ m => m.isEmpty
|
||||
| node ms => ms.all (·.isEmpty)
|
||||
| _ => false
|
||||
|
||||
/- Instantiate metavariables occurring in nexted `ofExpr` constructors.
|
||||
It uses the surrounding `MetavarContext` at `withContext` constructors.
|
||||
-/
|
||||
|
|
|
|||
|
|
@ -28,7 +28,10 @@ def mkFreshExprSyntheticOpaqueMVar (type : Expr) (tag : Name := Name.anonymous)
|
|||
mkFreshExprMVar type MetavarKind.syntheticOpaque tag
|
||||
|
||||
def throwTacticEx {α} (tacticName : Name) (mvarId : MVarId) (msg : MessageData) (ref := Syntax.missing) : MetaM α :=
|
||||
throwError "tactic '{tacticName}' failed, {msg}\n{MessageData.ofGoal mvarId}"
|
||||
if msg.isEmpty then
|
||||
throwError "tactic '{tacticName}' failed\n{MessageData.ofGoal mvarId}"
|
||||
else
|
||||
throwError "tactic '{tacticName}' failed, {msg}\n{MessageData.ofGoal mvarId}"
|
||||
|
||||
def throwNestedTacticEx {α} (tacticName : Name) (ex : Exception) : MetaM α := do
|
||||
throwError "tactic '{tacticName}' failed, nested error:\n{ex.toMessageData}"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue