unknown free variable for mutual def with incrementality
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- 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
Code here:
mutual
def a : Nat → Nat
| 0 => 1
| i + 1 => a i + b i
def b (i : Nat) : Nat := a i
def c (i : Nat) : Nat := b i
end
If you comment out the def c line, there's an error on the def a complaining about an unknown free variable. Uncommenting c fixes it, as does restarting file or just commenting and uncommenting the whole block.
Steps to Reproduce
- Comment out the
def cline, leaving a valid mutual def (as can be confirmed by restarting file) but that gives an error (for me, it'sunknown free variable '_fvar.10').
Expected behavior: No error when removing c.
Actual behavior: Code errors when removing c.
Versions
On live.lean-lang.org on lean nightly:
Lean 4.23.0-nightly-2025-08-11
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
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
Reproduce the mutual definition example in Lean 4.23.0-nightly-2025-08-11, comparing the block with and without def c and after restarting or reloading it. Then trace the incremental processing of mutual definitions and free-variable checking. Done means removing c produces no unknown-free-variable error, matching a freshly processed file.
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