leanprover / leanprover/lean4

stuck `simp` introduces metavariable; combined with `expose`, leads to panic later

Open
#12,730 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
Description

If simp makes no changes, this can sometimes lead to a declaration with metavariables (-> kernel error). If the declaration is public and exposed, later trying to apply the declaration's equational lemmas leads to a panic.

Using a declaration even after getting a kernel type error before is admittedly a questionable use case, but it might still be worthwhile to understand where the metavariable and panic are coming from, especially because it's somehow related to @[expose].

Reproduction steps

Consider this snippet:

module

/--
error: `simp` made no progress
---
error: (kernel) declaration has metavariables 'f'
-/
#guard_msgs in
@[expose] public def f (_ : Nat) : { xs : Unit // False } := ⟨sorry, by simp⟩

/--
error: unknown metavariable '?_uniq.24'
---
info: PANIC at Lean.MetavarContext.getDecl Lean.MetavarContext:450:17: unknown metavariable _uniq.24
backtrace:
PANIC at Lean.MetavarContext.getDecl Lean.MetavarContext:450:17: unknown metavariable _uniq.24
backtrace:
PANIC at Lean.MetavarContext.getDecl Lean.MetavarContext:450:17: unknown metavariable _uniq.24
backtrace:
---
error: (kernel) declaration has metavariables 'f.eq_1'
---
info: PANIC at Lean.MetavarContext.getDecl Lean.MetavarContext:450:17: unknown metavariable _uniq.24
backtrace:
---
warning: declaration uses `sorry`
-/
#guard_msgs in
theorem t : f 0 = sorry := by simp [f]

Expected behavior:

The simp in f's definition should fail. There should be no panics or kernel errors.

Actual behavior:

Defining f fails with a kernel error ("contains metavariables"), but the declaration is nonetheless created. If it's exposed, we get a panic when trying to simplify using f.eq_1.

Versions
Lean 4.30.0-nightly-2026-02-25
Target: x86_64-unknown-linux-gnu
Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the minimal reproduction in the issue and compare the simp and @[expose] behavior. Start at the reported Lean.MetavarContext.getDecl entry point and trace how the metavariable survives the kernel error and reaches the exposed equational lemma. Done means the failing definition is not created with metavariables and later simplification produces no panic or related kernel errors.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.