leanprover / leanprover/lean4

"Failed to compile definition" in `private` term of `noncomputable` declaration

Open
#9,868 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

[Clear and concise description of the issue]

Context

The private modifier can be used in field definitions structure constructors to prevent exposing the term. When using private inside a noncomputable declaration, the compiler throws an error if it fails to compile the private term.

Steps to Reproduce
  1. Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs1
  2. Open Reproductions/FailingIRCheck.lean and see the error message

Here's the code:

module

namespace X

public structure X

public instance : LE X where
  le _ _ := True

/--
error: failed to compile definition, compiler IR check failed at 'X.x._private_1._closed_0'. Error: depends on declaration 'Classical.propDecidable', which has no executable code; consider marking definition as 'noncomputable'
-/
#guard_msgs in
public noncomputable instance x : BEq X where
  beq a b := private haveI := Classical.propDecidable; a ≤ b ∧ b ≤ a

end X

Expected behavior:

No error. If the compiler tries and fails to compile any part of a noncomputable declaration, it should not complain and simply walk away without compiling it.

Actual behavior:

The compiler throws an error when it fails to compile the private term in the noncomputable declaration.

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 opening Reproductions/FailingIRCheck.lean from the linked reproduction project and run it with the reported Lean nightly version to confirm the IR-check error. Trace the compiler handling of private terms inside noncomputable declarations; done means the reproduced declaration compiles without reporting the private term's non-executable dependency.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.