leanprover / leanprover/lean4

Prop-to-bool coercion not working for `private` field definitions

Open
#9,874 0 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. 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
  1. Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs1
  2. Open Reproductions/PrivateCoercion.lean and 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.