Skip to content

Commit 0c43cd0

Browse files
digama0kim-em
andcommitted
fix: improve recall impl / error reporting (leanprover-community#8740)
This PR fixes `recall` to work inside namespaces and with `open` declarations, as reported on [Zulip](https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/recall.20doesn.27t.20work.20in.20namespaces/near/430877189). Previously, `recall` used raw `id.getId` to extract the declaration name, which ignored the current namespace. Now it uses `resolveGlobalConstNoOverload`, the standard Lean name resolution function. ```lean -- Previously failed with "Unknown constant 'myDef'" namespace Foo def myDef := 42 end Foo namespace Foo recall myDef : Nat -- now works end Foo -- Also works with `open` open Foo in recall myDef : Nat ``` 🤖 Prepared with Claude Code Co-authored-by: Kim Morrison <kim@tqft.net>
1 parent 425c494 commit 0c43cd0

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Mathlib/Tactic/Recall.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ elab_rules : command
5252
-- `recall` doesn't introduce new definitions, so suppress the unused variable linter.
5353
withScope (fun sc => { sc with opts := sc.opts.set `linter.unusedVariables false }) <|
5454
withoutModifyingEnv do
55-
let declName := id.getId
55+
let declName ← resolveGlobalConstNoOverload id
5656
addConstInfo id declName
5757
let info ← getConstInfo declName
5858
let declConst : Expr := mkConst declName <| info.levelParams.map Level.param

MathlibTest/Recall.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,16 @@ recall RecallUnivTest (R : Type v) : Prop
112112
-- Test that `recall` works with `Type*`.
113113
set_option linter.unusedVariables false in
114114
recall RecallUnivTest (R : Type*) : Prop
115+
116+
-- Test that `recall` works inside namespaces (https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/recall.20doesn.27t.20work.20in.20namespaces/near/430877189)
117+
namespace RecallTest
118+
def myDef := 42
119+
end RecallTest
120+
121+
namespace RecallTest
122+
recall myDef : Nat
123+
end RecallTest
124+
125+
-- Test that `recall` works with `open` namespaces.
126+
open RecallTest in
127+
recall myDef : Nat

0 commit comments

Comments
 (0)