lean4
lean4 copied to clipboard
`linter.unusedVariables` false positive when using `match` and `assumption`
Prerequisites
Please put an X between the brackets as you perform the following steps:
- [x] Check that your issue is not already filed: https://github.com/leanprover/lean4/issues
- [x] Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to Mathlib or Batteries.
- [x] 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
The unusedVariables linter reports a false positive on the theorem bad below:
inductive A where
| intro : Nat → A
def A.out : A → Nat
| .intro n => n
/--
warning: unused variable `h`
note: this linter can be disabled with `set_option linter.unusedVariables false`
-/
#guard_msgs in
theorem bad (n : A) (i : Nat) (h : i ≤ n.out) : i ≤ n.out :=
match n with
| .intro _ => by assumption
#guard_msgs in
theorem good₁ (n : A) (i : Nat) (h : i ≤ n.out) : i ≤ n.out := by
cases n with
| intro n => assumption
#guard_msgs in
theorem good₂ (n : A) (i : Nat) (h : i ≤ n.out) : i ≤ n.out := by
assumption
#guard_msgs in
theorem good₃ (n : A) (i : Nat) (h : i ≤ n.out) : i ≤ n.out :=
match n, h with
| .intro _, h => by assumption
-- Bodies of `bad` and `good₃` are identical:
/--
info: theorem bad : ∀ (n : A) (i : Nat), i ≤ n.out → i ≤ n.out :=
fun n i h =>
match n, h with
| A.intro a, h => h
-/
#guard_msgs in
#print bad
/--
info: theorem good₃ : ∀ (n : A) (i : Nat), i ≤ n.out → i ≤ n.out :=
fun n i h =>
match n, h with
| A.intro a, h => h
-/
#guard_msgs in
#print good₃
Context
There are several other issues about false positives of the unusedVariables linter. I have checked them and I believe that this is a new issue.
Steps to Reproduce
- Copy the code above into the Lean web editor
Expected behavior: Linter should not warn about bad
Actual behavior: Linter warns about bad
Versions
4.11.0-nightly-2024-07-09 on the Lean web editor
Impact
Add :+1: to issues you consider important. If others are impacted by this issue, please ask them to add :+1: to it.