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

feat: allow interpolation of fvars, with a warning #64

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Qq/ForLean/ReduceEval.lean
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def throwFailedToEval (e : Expr) : MetaM α :=

private partial def evalList [ReduceEval α] (e : Expr) : MetaM (List α) := do
let e ← whnf e
let .const c _ ← pure e.getAppFn | throwFailedToEval e
let .const c _ := e.getAppFn | throwFailedToEval e
let nargs := e.getAppNumArgs
match c, nargs with
| ``List.nil, 1 => pure []
Expand Down
6 changes: 5 additions & 1 deletion Qq/Macro.lean
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,12 @@ partial def unquoteExpr (e : Expr) : UnquoteM Expr := do
abstractedFVars := s.abstractedFVars.push fvarId
}
return fv
if let .fvar _ := e then
Lean.logWarning m!"Interpolated variable `{e}` should have type `Q(_)` not `{eTy}`. \
Adding `have {e} : Q(_) := {e}` may fix this."
return e
let e ← whnf e
let .const c _ ← pure e.getAppFn | throwError "unquoteExpr: {e} : {eTy}"
let .const c _ := e.getAppFn | throwError "unquoteExpr: {e} : {eTy}"
let nargs := e.getAppNumArgs
match c, nargs with
| ``betaRev', 2 => return betaRev' (← unquoteExpr (e.getArg! 0)) (← unquoteExprList (e.getArg! 1))
Expand Down
31 changes: 31 additions & 0 deletions examples/unquoteExprWarning.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Lean
import Qq.Macro

open Qq
open Lean Meta Elab Tactic Command

elab "iff_constructor" : tactic => do
let mvarId ← getMainGoal
let goalType ← getMainTarget

let_expr Iff a b := goalType
| throwError "Goal type is not of the form `a ↔ b`"

let a : Q(Prop) := a
let b : Q(Prop) := b

let mvarId1 ← mkFreshExprMVar q($a → $b) (userName := `mp)
let mvarId2 ← mkFreshExprMVar q($b → $a) (userName := `mpr)

let mvarId1 : Q($a → $b) := mvarId1
let mvarId2 : Q($b → $a) := mvarId2

mvarId.assign q(@Iff.intro $a $b $mvarId1 $mvarId2)

modify fun _ => { goals := [mvarId1.mvarId!, mvarId2.mvarId!] }

example (p q : Prop) (h1 : p → q) (h2 : q → p) : p ↔ q := by
iff_constructor

case mp => assumption
case mpr => assumption
Loading