This PR fixes a few bugs in the `rw` tactic: it could "steal" goals because they appear in the type of the rewrite, it did not do an occurs check, and new proof goals would not be synthetic opaque. This PR also lets the `rfl` tactic assign synthetic opaque metavariables so that it is equivalent to `exact rfl`. Implementation note: filtering old vs new is not sufficient. This PR partially addresses the bug where the rw tactic creates natural metavariables for each of the goals; now new proof goals are synthetic opaque. Metaprogramming API: Instead of `Lean.MVarId.rewrite` prefer `Lean.Elab.Tactic.elabRewrite` for elaborating rewrite theorems and applying rewrites to expressions. Closes #10172
33 lines
923 B
Text
33 lines
923 B
Text
/-!
|
|
# Rewrite tactic "steals" goals
|
|
-/
|
|
|
|
|
|
/-!
|
|
https://github.com/leanprover/lean4/issues/10172
|
|
|
|
There were two metaprogramming bugs:
|
|
- `rw` didn't filter old vs new metavariables when coming up with new goals.
|
|
- it also didn't make the new metavariables be synthetic opaque, so the old one was
|
|
being assigned, even with old vs new filtering.
|
|
-/
|
|
example (l m : List Nat) (i : Nat) (hi' : i < (l ++ m).length)
|
|
(hh : ∀ hi, l[i]'hi = 5) : (l ++ m)[i] = 5 := by
|
|
rw [List.getElem_append_left]
|
|
· rw [hh] -- used to be Error: unsolved goal `i < l.length`
|
|
· sorry -- used to be Error: No goals to be solved
|
|
|
|
/-!
|
|
While we're here, we could address a missing occurs check.
|
|
|
|
https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/rewrite.20with.20the.20goal/near/538108360
|
|
-/
|
|
/--
|
|
error: Occurs check failed: Expression
|
|
?k
|
|
contains the goal ?k
|
|
-/
|
|
#guard_msgs in
|
|
example : 1 = 2 := by
|
|
refine ?k
|
|
rw [?k]
|