Skip to content

generalizing does not work in match #29

@eric-wieser

Description

@eric-wieser

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions