feat: unfold should fail if it didn't unfold anything
This commit is contained in:
parent
4875224bd4
commit
e729b32b2b
3 changed files with 11 additions and 0 deletions
|
|
@ -33,11 +33,13 @@ where
|
|||
def unfoldTarget (mvarId : MVarId) (declName : Name) : MetaM MVarId := withMVarContext mvarId do
|
||||
let target ← instantiateMVars (← getMVarType mvarId)
|
||||
let r ← unfold target declName
|
||||
if r.expr == target then throwError "tactic 'unfold' failed to unfold '{declName}' at{indentExpr target}"
|
||||
applySimpResultToTarget mvarId target r
|
||||
|
||||
def unfoldLocalDecl (mvarId : MVarId) (fvarId : FVarId) (declName : Name) : MetaM MVarId := withMVarContext mvarId do
|
||||
let localDecl ← getLocalDecl fvarId
|
||||
let r ← unfold (← instantiateMVars localDecl.type) declName
|
||||
if r.expr == localDecl.type then throwError "tactic 'unfold' failed to unfold '{declName}' at{indentExpr localDecl.type}"
|
||||
let some (_, mvarId) ← applySimpResultToLocalDecl mvarId fvarId r (mayCloseGoal := false) | unreachable!
|
||||
return mvarId
|
||||
|
||||
|
|
|
|||
5
tests/lean/unfoldFailure.lean
Normal file
5
tests/lean/unfoldFailure.lean
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
example : True := by
|
||||
unfold Nat.add
|
||||
|
||||
example (h : x = 2 * y) : True := by
|
||||
unfold Nat.add at h
|
||||
4
tests/lean/unfoldFailure.lean.expected.out
Normal file
4
tests/lean/unfoldFailure.lean.expected.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
unfoldFailure.lean:2:2-2:16: error: tactic 'unfold' failed to unfold 'Nat.add' at
|
||||
True
|
||||
unfoldFailure.lean:5:2-5:21: error: tactic 'unfold' failed to unfold 'Nat.add' at
|
||||
x = 2 * y
|
||||
Loading…
Add table
Reference in a new issue