leanprover / leanprover/lean4

Stateful elaboration of mutual block causes 'unknown free variable'

Open
#8,223 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

Description

Consider the following block of code:

mutual

def foo : Nat -> Nat := fun n =>
  bar n

def bar : Nat -> Nat
  | 0 => 0
  | n+1 => foo n

def baz : Nat :=
  1

end

It elaborates correctly. However, if we then comment out baz, unknown free variable '_fvar.9' is reported on foo. This error is not 'real' in that upon restarting the file worker (or just making a change above the entire block), it goes away.

Expected behavior: Mutual block is re-elaborated correctly without refreshing.
Actual behavior: An error is reported.

Versions

Lean 4.20.0-nightly-2025-05-04
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 provided mutual-block reproducer with Lean 4.20.0-nightly-2025-05-04, then reproduce the failure by commenting out baz without restarting the file worker. Trace stateful elaboration of the mutual block; done means the block re-elaborates without an unknown free variable error after that edit.

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
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.