Usage of realizable constant `foo.eq_1` in privately imported module makes it private
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - 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
I have a situation where a module contains a public, exposed declaration x. Its equation x.eq_1 is public, but if a module imports another module privately that uses x.eq_1, then x.eq_1 is suddenly only available in the private context.
This suggests to me a problem with the handling of realizable constants.
Context
The problem occurred when I simped away instMonadLiftTOfMonadLift in some iterator module that was only privately imported into Std.Do.Triple.SpecLemmas but tried to assign the spec attribute to instMonadLiftTOfMonadLift.eq_1, which then failed because the constant was not in the public environment.
See https://github.com/leanprover/lean4/pull/10653; this PR uses the workaround of publicly importing the offending module into Std.Do.Triple.SpecLemmas.
Steps to Reproduce
- Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs4
- Open
Reproductions/Basic.leanand observe that Lean complains thatinstX.eq_1is not available in the public scope. (In fact, it even panics.)
module
public class X
@[expose]
public def x : X where
module
public import Reproductions.A
public theorem t : x = x := by
simp only [x]
module
public import Reproductions.A
import Reproductions.B
-- `x` has an exposed body:
/--
info: @[expose] def x : X :=
{ }
-/
#guard_msgs in
#print x
@[expose]
public def aa := x.eq_1
Either removing import Reproductions.B or making it a public import eliminates the error.
Expected behavior:
The additional import should have no effect on the visibility of x.eq_1. It should always be publicly available.
Actual behavior:
x.eq_1 is considered private in Basic.lean and using it in the public scope causes a panic.
Versions
Lean 4.25.0-nightly-2025-10-01
Target: arm64-apple-darwin23.6.0 macOS
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the reproducer in Reproductions/Basic.lean with Reproductions/A.lean and Reproductions/B.lean, comparing private and public imports. Trace how the exposed declaration x.eq_1 is made available across imports. Done means the extra private import neither changes public visibility nor causes the reported error or panic.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100