leanprover / leanprover/lean4

Usage of realizable constant `foo.eq_1` in privately imported module makes it private

Open
#10,652 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-high
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:

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
  1. Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs4
  2. Open Reproductions/Basic.lean and observe that Lean complains that instX.eq_1 is not available in the public scope. (In fact, it even panics.)

Reproductions/A.lean:

module

public class X

@[expose]
public def x : X where

Reproductions/B.lean:

module

public import Reproductions.A

public theorem t : x = x := by
  simp only [x]

Reproductions/Basic.lean:

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.