leanprover / leanprover/lean4

linter.unusedSectionVars: does not detect variable uses in where clauses

Open
#11,917 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

The unused section variable linter does not detect when a variable is used inside a where clause.

MWE
variable (n : Nat)
include n

theorem foo : ∃ (_ : Nat), True := by
  exists k
  where
  k := n + 1

This produces a warning:

automatically included section variable(s) unused in theorem 'foo':
  n
consider restructuring your `variable` declarations so that the variables are not in scope or explicitly omit them:
  omit n in theorem ...
note: this linter can be disabled with `set_option linter.unusedSectionVars false`

But n is used in the where clause (k := n + 1).

Discussion

https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/unused.20section.20variable.20linter.20is.20buggy/near/565224606

Note: the same Zulip thread also reports a related issue where the linter warns about an instance that cannot be omitted because it's referenced in the type of another included variable.

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 the MWE and tracing the unusedSectionVars linter entry point. Check why references from where clauses are missed, then verify that the example no longer reports n as unused. The linked Zulip discussion also notes a related instance-omission case that may need separate consideration.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.