Error when using public structure with private field of private type from a different module
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- 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
When trying to use a public structure with a private field of a private type in a different module, the compiler complains about not being to see the type of the private field, even though it should be unneeded.
Context
I was attempting to compose structures with private fields (for information hiding) across modules.
Steps to Reproduce
In Test.Basic:
module
private def Alias := Nat
public structure Wrapper where
private val : Alias
In Test.Other:
module
public import Test.Basic
/--
error: Unknown constant `_private.Test.Basic.0.Alias`
-/
#guard_msgs in
def wrapperId (wrapper : Wrapper) : Wrapper := wrapper
Expected behavior:
The definition of wrapperId should be accepted by the compiler as Wrapper's definition is public and it never tries to access the private field val.
Actual behavior:
The compiler complains about being unable to see the private Alias definition, even though it shouldn't be needed for this function:
error: Unknown constant `_private.Test.Basic.0.Alias`
Versions
4.29.0-nightly-2026-02-05
Ubuntu 24.04.3 LTS, GNU/Linux 6.14.0-37-generic, x86_64
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
Reproduce the issue using the Test.Basic and Test.Other modules, especially the wrapperId definition and its #guard_msgs check. Start by tracing how the compiler handles a public structure with a private field type across modules; done means wrapperId is accepted without the Unknown constant error.
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
- Clearly specified
- Newbie friendliness
- 48/100