chore: fix MVarId.getType' (#2595)

* chore: fix MVarId.getType'

* add test
This commit is contained in:
Scott Morrison 2023-10-09 22:04:33 +11:00 committed by GitHub
parent 41ed5ddf57
commit ca0e6b0522
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View file

@ -63,8 +63,11 @@ def getMVarType (mvarId : MVarId) : MetaM Expr :=
/-- Get the type the given metavariable after instantiating metavariables and reducing to
weak head normal form. -/
-- The `instantiateMVars` needs to be on the outside,
-- since `whnf` can unfold local definitions which may introduce metavariables.
-- We don't need an `instantiateMVars` before the `whnf`, since it instantiates as necessary.
def _root_.Lean.MVarId.getType' (mvarId : MVarId) : MetaM Expr := do
whnf (← instantiateMVars (← mvarId.getType))
instantiateMVars (← whnf (← mvarId.getType))
@[deprecated MVarId.getType']
def getMVarType' (mvarId : MVarId) : MetaM Expr := do

27
tests/lean/2505.lean Normal file
View file

@ -0,0 +1,27 @@
import Lean
open Lean Elab Tactic Meta
inductive A : Nat → Prop
def Lean.MVarId.getType'' (mvarId : MVarId) : MetaM Expr := do
instantiateMVars (← whnf (← mvarId.getType))
elab "the_target" : tactic => Tactic.withMainContext do
dbg_trace "target : {← (← getMainGoal).getType'}"
dbg_trace "target' : {← (← getMainGoal).getType''}"
example : True := by
let p := A ?n
case n => exact 1
have : p := ?h
case h =>
the_target
sorry
sorry
/-
Prior to #2595, this gave:
target : A ?_uniq.3033
target' : A (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))
-/

View file

@ -0,0 +1,3 @@
target : A (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))
target' : A (OfNat.ofNat.{0} Nat 1 (instOfNatNat 1))
2505.lean:14:0-14:7: warning: declaration uses 'sorry'