leanprover / leanprover/lean4

Error when using public structure with private field of private type from a different module

Open
#12,337 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-medium
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.