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

generalizing does not work in match #29

Closed
eric-wieser opened this issue Dec 10, 2023 · 1 comment · Fixed by leanprover/lean4#3060 or #33
Closed

generalizing does not work in match #29

eric-wieser opened this issue Dec 10, 2023 · 1 comment · Fixed by leanprover/lean4#3060 or #33

Comments

@eric-wieser
Copy link
Member

eric-wieser commented Dec 10, 2023

In the following example, I am forced to split a match into a Qq and non-Qq part:

import Qq
open Qq Lean

def pairNat₁ (u : Level) (α : Q(Type u)) (a : Q($α)) : MetaM (Q($α × $α)) :=
  match u, α, a with  -- error: Type mismatch `Nat` isn't `Type u`
  | Level.zero, ~q(Nat), ~q($n) => return q(($n, $n))
  | _, _, _ => throwError "only supported for `Nat`"

def pairNat₂ (u : Level) (α : Q(Type u)) (a : Q($α)) : MetaM (Q($α × $α)) :=
  match (generalizing := true) u, α, a with
  | Level.zero, ~q(Nat), ~q($n) => return q(($n, $n))  -- error: invalid pattern
  | _, _, _ => throwError "only supported for `Nat`"

-- works but ugly
def pairNat₃ (u : Level) (α : Q(Type u)) (a : Q($α)) : MetaM (Q($α × $α)) :=
  match (generalizing := true) u with
  | Level.zero =>
    match α, a with
    | ~q(Nat), ~q($n) => return q(($n, $n))
    | _, _ => throwError "only supported for `Nat`"
  | _ => throwError "only supported for `Nat`"

Caused by leanprover/lean4#3060, probably.

@eric-wieser
Copy link
Member Author

eric-wieser commented Dec 20, 2023

The first one is fixed by #31 when combined with leanprover/lean4#3060.

github-merge-queue bot pushed a commit to leanprover/lean4 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant