fix: Refactor mvar collection in assign tactic
This commit is contained in:
parent
e1b7eaab12
commit
0c469027c6
|
@ -4,7 +4,8 @@ open Lean
|
|||
|
||||
namespace Pantograph.Tactic
|
||||
|
||||
def assign (goal: MVarId) (expr: Expr): MetaM (List MVarId) := do
|
||||
/-- WARNING: This should be used with a function like `elabTermWithHoles` that properly collects the mvar information from `expr`. -/
|
||||
def assign (goal: MVarId) (expr: Expr) (nextGoals: List MVarId): MetaM (List MVarId) := do
|
||||
goal.checkNotAssigned `Pantograph.Tactic.assign
|
||||
|
||||
-- This run of the unifier is critical in resolving mvars in passing
|
||||
|
@ -12,19 +13,18 @@ def assign (goal: MVarId) (expr: Expr): MetaM (List MVarId) := do
|
|||
let goalType ← goal.getType
|
||||
unless ← Meta.isDefEq goalType exprType do
|
||||
throwError s!"{← Meta.ppExpr expr} : {← Meta.ppExpr exprType} ≠ {← Meta.ppExpr goalType}"
|
||||
|
||||
-- FIXME: Use `withCollectingNewGoalsFrom`. Think about how this interacts with elaboration ...
|
||||
let nextGoals ← Meta.getMVarsNoDelayed expr
|
||||
goal.assign expr
|
||||
nextGoals.toList.filterM (not <$> ·.isAssigned)
|
||||
nextGoals.filterM (not <$> ·.isAssigned)
|
||||
|
||||
def evalAssign : Elab.Tactic.Tactic := fun stx => Elab.Tactic.withMainContext do
|
||||
let target ← Elab.Tactic.getMainTarget
|
||||
let goal ← Elab.Tactic.getMainGoal
|
||||
goal.checkNotAssigned `Pantograph.Tactic.evalAssign
|
||||
let (expr, nextGoals) ← Elab.Tactic.elabTermWithHoles stx
|
||||
(expectedType? := .some target)
|
||||
(tagSuffix := .anonymous )
|
||||
(allowNaturalHoles := true)
|
||||
(← Elab.Tactic.getMainGoal).assign expr
|
||||
goal.assign expr
|
||||
Elab.Tactic.setGoals nextGoals
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue