Crash on overapplication of Quot.mk or trivial structures
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
The compiler crashes when the program contains an overapplication of an unsafeCast from Quot α _ to α or from a trivial wrapper to its sole parameter (both of which are documented as safe uses of unsafeCast).
Steps to Reproduce
Both of these crash:
unsafe def five : Nat := (unsafeCast (Quot.mk (fun _ _ => True) (· + 1)) : Nat → Nat) 4
#eval five
inductive Wrap where | mk (run : Nat → Nat)
unsafe def five : Nat := (unsafeCast (Wrap.mk (· + 1)) : Nat → Nat) 4
#eval five
Versions
Lean 4.34.0-nightly-2026-08-08
Target: x86_64-unknown-linux-gnu Linux
Additional Information
The root cause appears to be in LetValue.toMono where the overapplied arguments are dropped:
It looks like this issue was found before for Quot.lift and fixed in https://github.com/leanprover/lean4/pull/9827, but not for these other two cases, perhaps because they can only occur if combined with unsafeCast.
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 in src/Lean/Compiler/LCNF/ToMono.lean at LetValue.toMono around line 94, then run the two minimal unsafeCast examples from the issue. Compare the handling of overapplied arguments with the earlier Quot.lift fix in PR #9827; done means both examples compile and evaluate without crashing.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100