Skip to content

Commit de0f46b

Browse files
ymherklotztobiasgrosser
authored andcommitted
fix: wildcard generalize only generalizes visible theorems (leanprover#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
1 parent 82c58aa commit de0f46b

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Lean/Elab/Tactic/Generalize.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ open Meta
3030
args := args.push { hName?, expr, xName? := arg[3].getId : GeneralizeArg }
3131
let hyps ← match expandOptLocation stx[2] with
3232
| .targets hyps _ => getFVarIds hyps
33-
| .wildcard => pure (← getLCtx).getFVarIds
33+
| .wildcard => pure ((← getLocalHyps).map (·.fvarId!))
3434
let mvarId ← getMainGoal
3535
mvarId.withContext do
3636
let (_, newVars, mvarId) ← mvarId.generalizeHyp args hyps

tests/lean/4845.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/-!
2+
Generalize should not try to abstract the variable from hypotheses that are
3+
implementation details. -/
4+
5+
/-!
6+
In this case, generalize tries to revert the lemma being defined to generalize
7+
the 0 in it. -/
8+
9+
example : 0 = 0 → True := by
10+
intro H; generalize _H : 0 = z at *
11+
trace_state
12+
constructor

tests/lean/4845.lean.expected.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
z : Nat
2+
_H : 0 = z
3+
H : z = z
4+
⊢ True

0 commit comments

Comments
 (0)