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

let/ else pattern matching does not substitute in expected type #3065

Closed
1 task done
eric-wieser opened this issue Dec 13, 2023 · 0 comments · Fixed by #3060
Closed
1 task done

let/ else pattern matching does not substitute in expected type #3065

eric-wieser opened this issue Dec 13, 2023 · 0 comments · Fixed by #3060
Labels
bug Something isn't working

Comments

@eric-wieser
Copy link
Contributor

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Check that your issue is not already filed.
    • Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to mathlib4 or std4.

Description

let 3 := n | failure does not substitute n with 3 in the target type, even though equivalent spellings do.

Context

Zulip thread

This impacts leanprover-community/quote4, which transpiles to this type of let statement.

Steps to Reproduce

The following does not work:

example (n : Nat) (i : Fin n) : Option (Fin 3) := do
  let 3 := n | failure
  return i -- fails, pattern match did not substitute in hypothesis

example (n : Nat) (i : Fin 3) : Option (Fin n) := do
  let 3 := n | failure
  return i -- fails, pattern match did not substitute in goal

but the corresponding match does:

example (n : Nat) (i : Fin n) : Option (Fin 3) := do
  match n with
  | 3 => return i -- ok
  | _ => failure

example (n : Nat) (i : Fin 3) : Option (Fin n) := do
  match n with
  | 3 => return i -- ok
  | _ => failure

as does if let

example (n : Nat) (i : Fin n) : Option (Fin 3) := do
  if let 3 := n then
    return i
  else
    failure

example (n : Nat) (i : Fin 3) : Option (Fin n) := do
  if let 3 := n then
    return i
  else
    failure

Expected behavior: All three examples should behave identically

Actual behavior: The first one does not type-check

Versions

leanprover/lean4:v4.4.0-rc1

Additional Information

Impact

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

@eric-wieser eric-wieser added the bug Something isn't working label Dec 13, 2023
github-merge-queue bot pushed a commit that referenced this issue Jan 23, 2024
As suggested by @kmill, removing an unnecessary `let` (possibly only
there in the first place for copy/paste reasons) seems to fix the
included test.

This makes `~q()` matching in quote4 noticeably more useful in things
like `norm_num` (as it fixes
leanprover-community/quote4#29)

It also makes a quote4 bug slightly more visible
(leanprover-community/quote4#30), but the bug
there already existed anyway, and isn't caused by this patch.

Fixes #3065
@Kha Kha closed this as completed in #3060 Jan 23, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant