Skip to content

Commit

Permalink
chore: withLocation * should not fail if it closes the main goal (lea…
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-em authored Dec 12, 2023
1 parent fa26d22 commit 4b8c342
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/Lean/Elab/Tactic/Location.lean
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,11 @@ open Meta

/--
Runs the given `atLocal` and `atTarget` methods on each of the locations selected by the given `loc`.
* If `loc` is a list of locations, runs at each specified hypothesis (and finally the goal if `⊢` is included),
and fails if any of the tactic applications fail.
* If `loc` is `*`, runs at the target first and then the hypotheses in reverse order.
If `atTarget` closes the main goal, `withLocation` does not run `atLocal`.
If all tactic applications fail, `withLocation` with call `failed` with the main goal mvar.
If the tactic application closes the main goal, `withLocation` will then fail with `no goals to be solved`
upon reaching the first hypothesis.
-/
def withLocation (loc : Location) (atLocal : FVarId → TacticM Unit) (atTarget : TacticM Unit) (failed : MVarId → TacticM Unit) : TacticM Unit := do
match loc with
Expand All @@ -59,7 +57,8 @@ def withLocation (loc : Location) (atLocal : FVarId → TacticM Unit) (atTarget
withMainContext atTarget
| Location.wildcard =>
let worked ← tryTactic <| withMainContext <| atTarget
withMainContext do
let g ← try getMainGoal catch _ => return () -- atTarget closed the goal
g.withContext do
let mut worked := worked
-- We must traverse backwards because the given `atLocal` may use the revert/intro idiom
for fvarId in (← getLCtx).getFVarIds.reverse do
Expand Down

0 comments on commit 4b8c342

Please sign in to comment.