leanprover / leanprover/lean4

Unused variable linter false positives

Open
#13,354 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
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.