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

Antiquotations don't work for generic types (even if they implement ToExpr) #9

Open
alexkeizer opened this issue Apr 16, 2023 · 0 comments

Comments

@alexkeizer
Copy link

alexkeizer commented Apr 16, 2023

IIUC, when writing q($n) for, say n : Nat, it automatically translates $n into ToExpr.toExpr n.
This mechanism doesn't seem to work when we have an antiquotation of generic type \alpha, even if there is an instance of ToExpr \alpha in scope.

import Qq

open Lean
open Qq

-- Works
example (n : Nat) (m : Q(Nat)) : Q(Nat) :=
  q($n)

-- Doesn't work
example {α : Type} [ToExpr α]  (a : α) : Expr :=
  q($a)
--^^^^^ unknown free variable '_uniq.54'
--^^^^^ level mvars not supported ?u.69

-- Doesn't work either, but different error
example {α : Type} [ToExpr α]  (a : α) : QQ (toTypeExpr α) :=
  q($a)
--^^^^^ unquoteExpr: q.2 : Expr


-- Again, doesn't work, but now the error is even on the type declaration, too
example {α : Type} [ToExpr α]  (a : α) : Q($(toTypeExpr α)) :=
--                                       ^^^^^^^^^^^^^^^^^^ unquoteExpr: ?m.189 : Expr
  q($a)
--^^^^^ unquoteExpr: q.2 : Expr

When hovering my cursor over $a (in the Expr-returning example), I see the following context:

«$a»: _uniq.54
⊢ ?m.70

Which seems to suggest that the \alpha type (and the corresponding ToExpr) instance are not part of this local context, explaining why the antiquotation fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant