Zulip Chat Archive
Stream: mathlib4
Topic: PANIC at Mathlib.Tactic.GeneralizeProofs.mkLambdaFVarsUsedOn
Boris Alexeev (Dec 29 2025 at 01:33):
I encountered a PANIC deep into a monster Lean file. I believe the following is a minimal "working" example:
Boris Alexeev (Dec 29 2025 at 01:33):
import Mathlib
noncomputable def def1 (h : true) : ℕ := 0
noncomputable def def2 : ℕ := 0
theorem thm3 (n : ℕ) : true := by
have h_a :
let b := def2
let c := def1 (true)
true := by
all_goals generalize_proofs at *;
generalize_proofs at *;
Boris Alexeev (Dec 29 2025 at 01:33):
Boris Alexeev (Dec 29 2025 at 01:34):
The error on the "Lean 4 Web" site is:
Boris Alexeev (Dec 29 2025 at 01:34):
PANIC at Mathlib.Tactic.GeneralizeProofs.mkLambdaFVarsUsedOnly Mathlib.Tactic.GeneralizeProofs:208:11: unreachable code has been reached
backtrace:
PANIC at Mathlib.Tactic.GeneralizeProofs.mkLambdaFVarsUsedOnly Mathlib.Tactic.GeneralizeProofs:208:11: unreachable code has been reached
backtrace:
Snir Broshi (Dec 29 2025 at 01:35):
This is the unreachable code-
https://github.com/leanprover-community/batteries/blob/2e16f91af2a97975e5d2fac906494cd6c17ba255/Batteries/Tactic/GeneralizeProofs.lean#L210
Aaron Liu (Dec 29 2025 at 01:36):
I thought generalize proofs was in mathlib
Aaron Liu (Dec 29 2025 at 01:37):
did they move it to batteries
Aaron Liu (Dec 29 2025 at 01:39):
so the problem is once again the usedLetOnly option in docs#Lean.Meta.mkLambdaFVars being set to false by default means the result can be something other than a let or a lambda
Aaron Liu (Dec 29 2025 at 01:40):
this is #14444 which is still awaiting-author after more than a year
Snir Broshi (Dec 29 2025 at 01:44):
Tried to simplify the repro
import Batteries.Tactic.GeneralizeProofs
example :
let := true
let := (fun _ : True ↦ true) True
True := by
generalize_proofs
Snir Broshi (Dec 29 2025 at 01:45):
the type-error in the 2nd let seems necessary
Boris Alexeev (Dec 29 2025 at 01:47):
The problem did go away when I tried to fix the types. :)
Snir Broshi (Dec 29 2025 at 01:49):
Aaron Liu said:
so the problem is once again the
usedLetOnlyoption in docs#Lean.Meta.mkLambdaFVars being set to false by default means the result can be something other than a let or a lambda
Do you know what's the type that is returned?
Aaron Liu (Dec 29 2025 at 02:33):
no idea what you mean by that
Bryan Gin-ge Chen (Dec 29 2025 at 02:55):
Aaron Liu said:
this is #14444 which is still awaiting-author after more than a year
I'm sure @Mario Carneiro wouldn't mind if someone adopted this!
Snir Broshi (Dec 29 2025 at 03:09):
Aaron Liu said:
no idea what you mean by that
We know that mkLambdaFVars doesn't return a let, and doesn't return a lambda. So what does it return?
Aaron Liu (Dec 29 2025 at 03:13):
in this case it returns the body of the let, since the let-variable isn't used in the body
Aaron Liu (Dec 29 2025 at 03:14):
so since the let is constructed from the argument e, it just returns e unchanged
Aaron Liu (Dec 29 2025 at 03:15):
in your example depending on how it's used in the implementation I think this would probably be the constant True
Last updated: Feb 28 2026 at 14:05 UTC