lean4-htt/src/Lean/Meta/Tactic/Assumption.lean
Leonardo de Moura 7b6732a137 refactor: ExprDefEq.lean and LevelDefEq.lean are now implementation only files
We use the export/extern idiom to define `isLevelDefEqAux`, and then
define the `isDefEq` user facing functions at `Meta/Basic.lean`.
2021-12-06 09:57:00 -08:00

31 lines
1,014 B
Text

/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Tactic.Util
namespace Lean.Meta
/-- Return a local declaration whose type is definitionally equal to `type`. -/
def findLocalDeclWithType? (type : Expr) : MetaM (Option FVarId) := do
(← getLCtx).findDeclRevM? fun localDecl => do
if localDecl.isAuxDecl then
return none
else if (← isDefEq type localDecl.type) then
return some localDecl.fvarId
else
return none
def assumptionCore (mvarId : MVarId) : MetaM Bool :=
withMVarContext mvarId do
checkNotAssigned mvarId `assumption
match (← findLocalDeclWithType? (← getMVarType mvarId)) with
| none => return false
| some fvarId => assignExprMVar mvarId (mkFVar fvarId); return true
def assumption (mvarId : MVarId) : MetaM Unit :=
unless (← assumptionCore mvarId) do
throwTacticEx `assumption mvarId ""
end Lean.Meta