Skip to content

Commit

Permalink
fix: wildcard generalize only generalizes visible theorems (leanpro…
Browse files Browse the repository at this point in the history
…ver#4846)

`generalize ... at *` sometimes will try to modify the recursive
hypothesis corresponding to the current theorem being defined, which may
not be the expected behaviour. It should only try to `generalize`
hypotheses that it can actually modify and are visible, not
implementation details. Otherwise this means that there are
discrepancies between `generalize ... at *` and `generalize ... at H`,
even though `H` is the only hypothesis in the context.

This commit uses `getLocalHyps` instead of `getFVarIds` to get the
current valid `FVarIds` in the context. This uses
`isImplementationDetail` to filter out `FVarIds` that are implementation
details in the context and are not visible to the user and should not be
manipulated by `generalize`.

Closes leanprover#4845
  • Loading branch information
ymherklotz authored and tobiasgrosser committed Oct 27, 2024
1 parent 82c58aa commit de0f46b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Lean/Elab/Tactic/Generalize.lean
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ open Meta
args := args.push { hName?, expr, xName? := arg[3].getId : GeneralizeArg }
let hyps ← match expandOptLocation stx[2] with
| .targets hyps _ => getFVarIds hyps
| .wildcard => pure (← getLCtx).getFVarIds
| .wildcard => pure ((← getLocalHyps).map (·.fvarId!))
let mvarId ← getMainGoal
mvarId.withContext do
let (_, newVars, mvarId) ← mvarId.generalizeHyp args hyps
Expand Down
12 changes: 12 additions & 0 deletions tests/lean/4845.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/-!
Generalize should not try to abstract the variable from hypotheses that are
implementation details. -/

/-!
In this case, generalize tries to revert the lemma being defined to generalize
the 0 in it. -/

example : 0 = 0 → True := by
intro H; generalize _H : 0 = z at *
trace_state
constructor
4 changes: 4 additions & 0 deletions tests/lean/4845.lean.expected.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
z : Nat
_H : 0 = z
H : z = z
⊢ True

0 comments on commit de0f46b

Please sign in to comment.