Prop-to-bool coercion not working for `private` field definitions
Nobody has claimed this yet.
- 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:
- 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 assigning the fields of a structure, the private modifier can be used. When the field is Bool-valued and the private term is a decidable Prop, Lean fails to apply the coercion to Bool.
Steps to Reproduce
- Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs1
- Open
Reproductions/PrivateCoercion.leanand observe that Lean reports a type mismatch.
Here's the code:
module
/--
error: Type mismatch
instBEq._private_1
has type
Prop
but is expected to have type
Bool
-/
#guard_msgs in
public instance instBEq {α : Type u} [LE α] [DecidableLE α] :
BEq α where
beq _ _ := private True
-- works because `True` is coerced into `decide True`
public instance instBEq' {α : Type u} [LE α] [DecidableLE α] :
BEq α where
beq _ _ := True
Expected behavior:
Like when private is omitted, Lean should correctly insert a decide application to make a Bool out of True.
Actual behavior:
Lean fails and complains about the type mismatch.
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
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
Start by running the minimal reproduction in Reproductions/PrivateCoercion.lean from the linked bugs1 branch and confirm the type mismatch. Trace how private field definitions are elaborated compared with the working public instance. Done means the private Bool-valued field accepts the decidable Prop through the same coercion as the non-private case, with the reproduction passing.
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
- 45/100