fix: bug in replaceLocalDeclDefEq

fixes #1615
This commit is contained in:
Mario Carneiro 2022-11-01 18:28:35 -04:00 committed by Leonardo de Moura
parent 00e3004ce5
commit ad1c23f172
2 changed files with 19 additions and 2 deletions

View file

@ -99,10 +99,10 @@ Remark: this method assumes that `typeNew` is definitionally equal to the curren
-/
def _root_.Lean.MVarId.replaceLocalDeclDefEq (mvarId : MVarId) (fvarId : FVarId) (typeNew : Expr) : MetaM MVarId := do
mvarId.withContext do
let mvarDecl ← mvarId.getDecl
if typeNew == mvarDecl.type then
if typeNew == (← fvarId.getType) then
return mvarId
else
let mvarDecl ← mvarId.getDecl
let lctxNew := (← getLCtx).modifyLocalDecl fvarId (·.setType typeNew)
let mvarNew ← mkFreshExprMVarAt lctxNew (← getLocalInstances) mvarDecl.type mvarDecl.kind mvarDecl.userName
mvarId.assign mvarNew

17
tests/lean/run/1615.lean Normal file
View file

@ -0,0 +1,17 @@
import Lean.Elab.ElabRules
import Lean.Meta.Tactic.Replace
elab "test" h:ident : tactic => do
let g ← Lean.Elab.Tactic.getMainGoal
g.withContext do
let ldec ← Lean.Meta.getLocalDeclFromUserName h.getId
let f := ldec.fvarId
let e ← Lean.Meta.whnf (← Lean.instantiateMVars ldec.type)
let newgoal ← g.replaceLocalDeclDefEq f e
Lean.Elab.Tactic.replaceMainGoal [newgoal]
def Nat.dvd (a b : Nat) := ∃ c, b = a * c
example (n : Nat) (h : Nat.dvd 2 n) : ∃ c, n = 2 * c := by
test h
with_reducible exact h