Unused variable linter false positives
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
universe u
example (f : Type u → Type (u + 1)) :
(Σ (X : Type u) (Y : Type u), Unit → X → Y) → Type (u + 1) :=
fun (⟨X, Y, _⟩ : Σ (X : Type u) (Y : Type u), Unit → X → Y) ↦ (f X → f Y)
-- ^ unused variable linter triggers here
#eval show Id _ from do
let vals := #[1, 2]
let rec go xs acc := do
-- ^ ^ unused variable linter triggers here
if h : xs.size = 0 then
acc
else
go xs[1:] (acc.push xs[0])
go vals #[]
The first one is interesting because the linter triggers on something that doesn't even declare a variable.
The second one seems to be specific to #eval; if you change it into a partial def then the error goes away.
Context
Reported at #new members > "Unused variable" that is clearly not unused
Expected behavior: No unused variable warnings
Actual behavior: Unused variable warnings
Versions
Lean 4.31.0-nightly-2026-04-09 on live.lean-lang.org
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 by reproducing both minimal examples in the Lean nightly environment, checking the reported unused-variable locations. Compare the #eval case with the partial def version and confirm that the fix eliminates both false-positive warnings without introducing new ones.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100