leanprover / leanprover/lean4

`simp` cannot unfold field definition marked as `private`

Open
#9,872 2 comments 0 reactions 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

Please put an X between the brackets as you perform the following steps:

Description

When assigning the fields of a structure, the private modifier can be used. It creates unexposed helper declarations. In some situations, it is not possible to unfold them, making them effectively opaque.

Steps to Reproduce
  1. Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs1
  2. Open Reproductions/UnfoldingPrivate.lean and observe that the _private_ constant cannot be unfolded.

Here's the code:

module

public noncomputable instance instBEq {α : Type u} [LE α] [DecidableLE α] :
    BEq α where
  beq _ _ := private true

-- UPDATE: Ignore this first example. This is expected to fail because
-- True.intro is of type `True`, while we expect a value of type `true = true`.
/--
error: Type mismatch
  True.intro
has type
  True
but is expected to have type
  instBEq._private_1 = true
-/
#guard_msgs in
private theorem eq_of_beq [LE α] [DecidableLE α] (a b : α) : a == b := by
  simp only [BEq.beq]
  exact True.intro

/--
error: trying to realize `_private.Lean.Environment.0.Lean.Environment.RealizeConstKey` value but `enableRealizationsForConst` must be called for 'instBEq._private_1' first
---
error: unsolved goals
α : Type u_1
inst✝¹ : LE α
inst✝ : DecidableLE α
a b : α
⊢ instBEq._private_1 = true
-/
#guard_msgs in
private theorem eq_of_beq' [LE α] [DecidableLE α] (a b : α) : a == b := by
  simp only [BEq.beq, instBEq._private_1]

Expected behavior:

The helper declaration should be reducible or even semireducible in public contexts. (It is!) (d)simp should be able to unfold the helper declaration.

Alternatively, private should only be allowed for propositions and forbidden for other expected types.

Actual behavior:

Cannot unfold at all, there seems to be no way to finish my proof.
Cannot prove the theorem using only simp.

Versions
Lean 4.23.0-nightly-2025-08-11
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 minimal reproduction in Reproductions/UnfoldingPrivate.lean against the stated Lean nightly, then inspect how simp handles instBEq._private_1 after BEq.beq is unfolded. Done means the final #guard_msgs case proves the equality using simp without enabling realizations or leaving an unsolved goal.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.