fix: case tactic in macros (#4252)

We must erase macro scopes for tags in `case` as we do in `cases .. with
..` and `induction .. with ..`.
This commit is contained in:
Leonardo de Moura 2024-05-23 02:01:24 +02:00 committed by GitHub
parent f97a7d4234
commit 2bc41d8f3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -469,7 +469,7 @@ def renameInaccessibles (mvarId : MVarId) (hs : TSyntaxArray ``binderIdent) : Ta
private def getCaseGoals (tag : TSyntax ``binderIdent) : TacticM (MVarId × List MVarId) := do
let gs ← getUnsolvedGoals
let g ← if let `(binderIdent| $tag:ident) := tag then
let tag := tag.getId
let tag := tag.getId.eraseMacroScopes
let some g ← findTag? gs tag | notFound gs tag
pure g
else

View file

@ -0,0 +1,22 @@
def f (n : Nat) := n + 1
macro "mymacro1 " h:ident : tactic =>
`(tactic| {
cases $h:ident with
| zero => decide
| succ => simp_arith [f]
})
example : f n > 0 := by
mymacro1 n -- works
macro "mymacro2 " h:ident : tactic =>
`(tactic| {
cases $h:ident
case zero => decide
case succ => simp_arith [f]
})
example : f n > 0 := by
-- Should **not** generate: Case tag 'zero._@.cases3._hyg.747' not found.
mymacro2 n