leanprover / leanprover/lean4

unknown free variable for mutual def with incrementality

Open
#9,858 1 comment 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

Please put an X between the brackets as you perform the following steps:

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
  1. Comment out the def c line, leaving a valid mutual def (as can be confirmed by restarting file) but that gives an error (for me, it's unknown 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.