matcher created in `def f := ...` body is private but occurs in type
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
Consider this situation:
module
public import Std
open Std
public section
def step : Nat × Nat → Nat × Nat
| (x₁, x₂) => (x₂, x₁ + x₂)
def statesIterator := Iter.repeat (init := (0, 1)) step
/--
error: Unknown constant `_private.«external:file:///lean-nightly/lean-nightly.lean».0.step.match_1`
Note: A private declaration `step.match_1` (from the current module) exists but would need to be public to access here.
-/
#guard_msgs in
def fibIterator := statesIterator.map (fun (current, _) => current)
Here, the iterator fibIterator's type is inferred from its definition. This type also contains the lambda function in the map expression. Therefore, the matcher used by the lambda function, fibIterator.match_1, is going to be contained in fibIterator's type, which is public.
Expected behavior: [Clear and concise description of what you expect to happen]
No errors; fibIterator.match_1 should be public.
Actual behavior: [Clear and concise description of what actually happens]
Error: fibIterator.match_1 was made private and therefore can't occur in fibIterator's public type.
An even more minified example
module
/--
error: Unknown constant `_private.«external:file:///lean-nightly/lean-nightly.lean».0.vec.match_1`
Note: A private declaration `vec.match_1` (from the current module) exists but would need to be public to access here.
-/
#guard_msgs in
public def vec (n : Nat) := Vector.replicate (match n with | 0 => 0 | n' + 1 => n')
Versions
Lean 4.29.0-nightly-2026-02-14
Target: x86_64-unknown-linux-gnu
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 with the minimal public def vec example and the step/fibIterator example using the Lean nightly version described, observing the #guard_msgs errors. Trace how the generated matcher is assigned visibility when it appears in an inferred public type; done means both examples elaborate without the private-declaration 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
- 35/100