Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect unused variable warning in lambda with pattern match and type signature #6264

Open
3 tasks done
mniip opened this issue Nov 30, 2024 · 2 comments
Open
3 tasks done
Labels
bug Something isn't working P-medium We may work on this issue if we find the time

Comments

@mniip
Copy link

mniip commented Nov 30, 2024

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

Incorrect "unused variable" warnings are reported around lambdas with pattern matches and explicit type annotations. See example below.

Context

Steps to Reproduce

#check λα (p : α → Prop) (⟨x, _⟩ : {a // p a}) => x
--         ^                             ^ ^
--         1                             2 3

Expected behavior: No unused variable warnings.

Actual behavior: Lean reports 3 unused variable warnings at the indicated locations:

  • Lean claims p at location 1 is unused, even though though 2 is its use.
  • Lean claims p at location 2 and a at location 3 are unused, even though these are not the variables' binding sites.

Versions

4.13.0

Additional Information

The "2" warning goes away if we use p in the body of the lambda:

#check λα (p : α → Prop) (⟨x, _⟩ : {a // p a}) => (x, p)
--         ^                             ^ ^
--         1                             2 3

as if Lean believes 2 is p's binding site which in turn shadows the p bound at 1.

The problem goes away if matching is moved out of the lambda:

#check λα (p : α → Prop) (x : {a // p a}) => match x with | ⟨x, _⟩ => x

The use of (Subtype.mk _ _) versus ⟨_, _⟩ makes no difference.

Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

@mniip mniip added the bug Something isn't working label Nov 30, 2024
@digama0
Copy link
Collaborator

digama0 commented Nov 30, 2024

  • Lean claims p at location 2 and a at location 3 are unused, even though these are not the variables' binding sites.

This behavior is indicative of an auto implicit, which has its definition site set to the first use if the variable.

@Kha
Copy link
Member

Kha commented Dec 6, 2024

This is a bug in the match compiler:

/- If `p` is a free variable and we are not inside of an "inaccessible" pattern, this `p` is a binder. -/
mkTermInfo Name.anonymous stx p (isBinder := p.isFVar && !(← read))

@leanprover-bot leanprover-bot added the P-medium We may work on this issue if we find the time label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P-medium We may work on this issue if we find the time
Projects
None yet
Development

No branches or pull requests

4 participants