`simp` uses `congr` lemmas that are not visible
Prerequisites
Please put an X between the brackets as you perform the following steps:
- [x] Check that your issue is not already filed: https://github.com/leanprover/lean4/issues
- [x] Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to Mathlib or Batteries.
- [x] Test your test case against the latest nightly release, for example on https://live.lean-lang.org/#project=lean-nightly (You can also use the settings there to switch to “Lean nightly”)
Description
Private lemmas marked as @[congr] from imported modules are used by simp even though they are not visible, causing unknown constant errors.
Steps to Reproduce
- Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs7
- Open
Reproductions/Basic.leanand observe the error.
Reproductions/Dependency.lean:
module
public def f : Nat → Nat := sorry
@[congr]
theorem t (h : m = n) : f m = f n := sorry
module
import Reproductions.Dependency
/-- error: Unknown constant `_private.Reproductions.Dependency.0.t` -/
#guard_msgs in
theorem u (h : m = n) : f m = f n := by
simp [h]
Expected behavior:
simp should only use congr lemmas that are visible. (In the given example, theorem u should succeed because simp actually doesn't need to use a specialized congr lemma.)
Actual behavior:
An unknown constant error is caused by simp.
Versions
Lean 4.27.0-nightly-2025-11-30
Target: arm64-apple-darwin24.6.0 macOS
Impact
Add :+1: to issues you consider important. If others are impacted by this issue, please ask them to add :+1: to it.
Probably a missing exportEntry function that prevents these entries from entering the public environment in the first place, somewhere near
https://github.com/leanprover/lean4/blob/057b70b443d99c08be8b0f193cfa0690b42d0185/src/Lean/Meta/Tactic/Simp/SimpCongrTheorems.lean#L49
or - if possible - in SimpleScopedEnvExtension directly in
https://github.com/leanprover/lean4/blob/057b70b443d99c08be8b0f193cfa0690b42d0185/src/Lean/ScopedEnvExtension.lean#L246
so that all users benefit