lean4-htt/tests/lean/run/issue4726.lean
Joachim Breitner f0eab4b7b1
fix: nested structural recursion over reflexive data type (#4728)
this code
```
inductive N where
 | cons : (Nat -> N) -> N

mutual
def f : N -> Nat
 | .cons a => g (a 32) + 1
termination_by structural n => n
def g : N -> Nat
 | .cons a => f (a 42) + 1
termination_by structural  n => n
end
```
would break. When searching for the right `belowDict` we now have to,
evne after instantiating the paramters for a reflexive argument, again
search through a bunch of `PProd`s.

(Instead of searching we could pass down the index, but since we are
searching anyways in this function let's just re-use.)

Fixes: #4726
2024-07-11 15:25:48 +00:00

17 lines
458 B
Text

-- A refexive type, with multiple parameters to make sure
-- we get the order right
inductive N where
| cons : (Nat -> Bool → N) -> N
-- set_option trace.Elab.definition.structural true
mutual
def f : N -> List Nat → List Bool → Nat
| .cons a, _, _ => g (a 32 true) [true] [1] + 1
termination_by structural n => n
def g : N -> List Bool → List Nat → Nat
| .cons a, _, _ => f (a 42 false) [1] [true] + 1
termination_by structural n => n
end