leanprover / leanprover/lean4

Crash on overapplication of Quot.mk or trivial structures

Open
#14,719 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites
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:

https://github.com/leanprover/lean4/blob/f29e9e488ea8242c875806e4b0564820c2d553b2/src/Lean/Compiler/LCNF/ToMono.lean#L94

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.