"Failed to compile definition" in `private` term of `noncomputable` declaration
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
[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
- Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs1
- Open
Reproductions/FailingIRCheck.leanand 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
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 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