lean4
lean4 copied to clipboard
Mutual recursion and `@[specialize]` lead to `(kernel) deep recursion detected`
Prerequisites
Please put an X between the brackets as you perform the following steps:
- [x] Check that your issue is not already filed: https://github.com/leanprover/lean4/issues
- [x] Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to Mathlib or Batteries.
- [x] 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
In the following code, applying the function g leads to the error (kernel) deep recursion detected.
def g (f : Nat → Nat) (n : Nat) : Nat :=
inner n
where
@[specialize] inner (n : Nat) : Nat :=
if n = 0 then 0 else g f (n - 1)
/-- error: (kernel) deep recursion detected -/
#guard_msgs in
def x := g (fun _ => 0) 0
Steps to Reproduce
- Copy the above code into the Lean web editor
Expected behavior: No error message
Actual behavior: (kernel) deep recursion detected
Versions
4.11.0-nightly-2024-07-10
Impact
Add :+1: to issues you consider important. If others are impacted by this issue, please ask them to add :+1: to it.