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

~q pattern match does not respect return #21

Open
Vtec234 opened this issue Aug 7, 2023 · 4 comments
Open

~q pattern match does not respect return #21

Vtec234 opened this issue Aug 7, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@Vtec234
Copy link
Contributor

Vtec234 commented Aug 7, 2023

Consider the snippet below. I would expect the two functions foo₁ and foo₂ to be equivalent and both to work, however foo₁ fails to elaborate with a type error.

import Lean
import Qq

open Lean Meta
open Qq

def foo₁ (T : Q(Type)) (t : Q($T)) : MetaM Q($T) := do
  if let ~q(Prop) := T then
    /- type mismatch
      q(True)
    has type
      Q(Prop) : Type
    but is expected to have type
      PUnit : Type -/
    return q(True)
  return q($t)

def foo₂ (T : Q(Type)) (t : Q($T)) : MetaM Q($T) := do
  match T with
  | ~q(Prop) => return q(True)
  | _ => return q($t)
@eric-wieser
Copy link
Member

eric-wieser commented Nov 15, 2023

I think the return is operating at the wrong scope:

def foo₁ (T : Q(Type)) : MetaM Bool := do
  if let ~q(Prop) := T then
    return ()
  return true

It's returning from the inner macro, not the outer do block

@eric-wieser eric-wieser added the bug Something isn't working label Nov 15, 2023
@eric-wieser
Copy link
Member

eric-wieser commented Nov 15, 2023

Here's a slightly more damning example:

import Qq
open Qq Lean

def foo₂ (T : Q(Type)) : MetaM Bool := do
  let x : Unit ← match T with
    | ~q(Prop) => return true
    | _ => return true
  return false

#eval foo₂ q(Nat)  -- false
#eval foo₂ q(Int)  -- false

@eric-wieser eric-wieser changed the title ~q pattern match under if let has wrong type ~q pattern match does not respect return Nov 15, 2023
eric-wieser added a commit that referenced this issue Nov 15, 2023
@eric-wieser
Copy link
Member

I added a lot of test-cases in #27

@eric-wieser
Copy link
Member

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

No branches or pull requests

2 participants