`Meta.check` Fails After `revert`
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
This is an issue with delayed assigned metavariables. In the context of a metavariable, if the target type contains another metavariable, and some free variable gets reverted, Meta.check fails.
Context
Steps to Reproduce
- Execute the following snippet either in LSP or
lean --run
import Lean
open Lean
#eval do
let statement ← instantiateMVars $ ← Elab.Term.elabTerm (← `(term|forall (n m: Nat) (h: n = m), n.succ = m.succ)) .none
Meta.forallTelescope statement λ _fvars target => do
let .some (β, _, _) := (← instantiateMVars target).eq? | throwError "Goal is not an Eq"
let u ← Meta.mkFreshLevelMVar
let α ← Meta.mkFreshExprSyntheticOpaqueMVar (mkSort u)
let f ← Meta.mkFreshExprSyntheticOpaqueMVar (.forallE .anonymous α β .default)
let a₁ ← Meta.mkFreshExprSyntheticOpaqueMVar α
let a₂ ← Meta.mkFreshExprSyntheticOpaqueMVar α
let h ← Meta.mkFreshExprSyntheticOpaqueMVar (← Meta.mkEq a₁ a₂)
let fvars := (← h.mvarId!.getDecl).lctx.foldl (init := []) λ acc decl => acc ++ [decl.fvarId]
let (_, h') ← h.mvarId!.revert #[fvars[2]!] true
h'.withContext do
Meta.check (← h'.getType)
Expected behavior:
Meta.check succeeds, so nothing gets printed.
Actual behavior:
Mystery.lean:4:0: error: Application type mismatch: The argument
?m.5
has type
?m.3
but is expected to have type
?m.3
in the application
Eq ?m.5
Note that the two ?m.3 are different. Set pp.all true to see.
Versions
Lean (version 4.28.0-nightly-2026-01-12, x86_64-unknown-linux-gnu, commit e56351da7ae15673a5bc2b83e7fb70e1fbd988ca, Release)
Also occurs on 4.27.0
on Arch Linux
Also happens in Lean v4.26.0
Additional Information
This is related to #5279
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the self-contained Lean snippet in the issue and run it using lean --run or in LSP. Investigate the interaction between delayed assigned metavariables, Meta.forallTelescope, revert, and Meta.check, with related issue #5279 as context. Done means the reproduction succeeds without the application type mismatch.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100