fix: unresolve name avoiding locals (#4593)
Fixes #4591. The extra code already existed in the only other user of `unresolveNameGlobal` (in the pretty printer), although I did not make it use this function because it has some additional behavior around universes and in pattern position.
This commit is contained in:
parent
e9d2f8f5f2
commit
4a2210b7e6
4 changed files with 20 additions and 1 deletions
|
|
@ -347,7 +347,7 @@ def mkSimpOnly (stx : Syntax) (usedSimps : Simp.UsedSimps) : MetaM Syntax := do
|
|||
if env.contains declName
|
||||
&& (inv || !simpOnlyBuiltins.contains declName)
|
||||
&& !Match.isMatchEqnTheorem env declName then
|
||||
let decl : Term ← `($(mkIdent (← unresolveNameGlobal declName)):ident)
|
||||
let decl : Term ← `($(mkIdent (← unresolveNameGlobalAvoidingLocals declName)):ident)
|
||||
let arg ← match post, inv with
|
||||
| true, true => `(Parser.Tactic.simpLemma| ← $decl:term)
|
||||
| true, false => `(Parser.Tactic.simpLemma| $decl:term)
|
||||
|
|
|
|||
|
|
@ -425,4 +425,15 @@ where
|
|||
return some candidate
|
||||
return none
|
||||
|
||||
def unresolveNameGlobalAvoidingLocals [Monad m] [MonadResolveName m] [MonadEnv m] [MonadLCtx m]
|
||||
(n₀ : Name) (fullNames := false) : m Name := do
|
||||
let mut n ← unresolveNameGlobal n₀ fullNames
|
||||
unless (← getLCtx).usesUserName n do return n
|
||||
-- `n` is also a local declaration
|
||||
if n == n₀ then
|
||||
-- `n` is the fully qualified name. So, we append the `_root_` prefix
|
||||
return `_root_ ++ n
|
||||
else
|
||||
return n₀
|
||||
|
||||
end Lean
|
||||
|
|
|
|||
7
tests/lean/4591.lean
Normal file
7
tests/lean/4591.lean
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def Nat.foo : Nat → Nat
|
||||
| 0 => 0
|
||||
| n+1 => foo n
|
||||
decreasing_by decreasing_tactic
|
||||
|
||||
theorem Nat.Bar.foo : foo 2 = 0 := by
|
||||
simp? [Nat.foo]
|
||||
1
tests/lean/4591.lean.expected.out
Normal file
1
tests/lean/4591.lean.expected.out
Normal file
|
|
@ -0,0 +1 @@
|
|||
Try this: simp only [Nat.foo]
|
||||
Loading…
Add table
Reference in a new issue