Skip to content

Commit

Permalink
fix: inaccessible pattern vars reported as binders (#5337)
Browse files Browse the repository at this point in the history
Fixes an unused variable false positive on some wildcard patterns

Fixes #1633, fixes #2830
  • Loading branch information
Kha authored Sep 13, 2024
1 parent ec98c92 commit 438061a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Lean/Elab/Match.lean
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ where
| .proj _ _ b => return p.updateProj! (← go b)
| .mdata k b =>
if inaccessible? p |>.isSome then
return mkMData k (← withReader (fun _ => false) (go b))
return mkMData k (← withReader (fun _ => true) (go b))
else if let some (stx, p) := patternWithRef? p then
Elab.withInfoContext' (go p) fun p => do
/- If `p` is a free variable and we are not inside of an "inaccessible" pattern, this `p` is a binder. -/
Expand Down
7 changes: 7 additions & 0 deletions tests/lean/linterUnusedVariables.lean
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,10 @@ def ignoreEverything : Lean.Linter.IgnoreFunction :=
fun _ _ _ => true

def ignored (x : Nat) := 0

/-!
The wildcard pattern introduces a copy of `x` that should not be linted as it is in an
inaccessible annotation.
-/
example : (x = y) → y = x
| .refl _ => .refl _

0 comments on commit 438061a

Please sign in to comment.