lean4-htt/tests/lean/run/issue5061.lean
Joachim Breitner c78bb62c51
fix: get_elem_tactic_trivial to not loop in the presence of mvars (#5119)
The goal at the crucial step is
```
a : Array Nat
i : Fin ?m.27
⊢ ↑i < a.size
```
and after the `apply Fin.val_lt_of_le;` we have
```
a : Array Nat
i : Fin ?m.27
⊢ ?m.27 ≤ a.size
```
and now `apply Fin.val_lt_of_le` applies again, due to accidential
defeq. Adding `with_reducible` helps here.

fixes #5061
2024-08-21 19:51:58 +00:00

33 lines
1.1 KiB
Text

opaque fin_max {n: Nat} (f: Fin n → Nat) : Nat
set_option maxRecDepth 30 in
-- NB: Important to not specify the implicit argument of fin_max here
def test (a: Array Nat) : Nat := @fin_max _ fun i =>
let h : i < a.size := by
-- this may apply once
with_reducible apply Fin.val_lt_of_le
fail_if_success with_reducible apply Fin.val_lt_of_le;
exact Nat.le_refl _
a.get ⟨i, h⟩
set_option pp.mvars false
-- This used to cause
-- error: maximum recursion depth has been reached in #5061
/--
error: failed to prove index is valid, possible solutions:
- Use `have`-expressions to prove the index is valid
- Use `a[i]!` notation instead, runtime check is perfomed, and 'Panic' error message is produced if index is not valid
- Use `a[i]?` notation instead, result is an `Option` type
- Use `a[i]'h` notation instead, where `h` is a proof that index is valid
a : Array Nat
i : Fin ?_
⊢ ↑i < a.size
-/
#guard_msgs in
set_option maxRecDepth 40 in
def test2 (a: Array Nat) : Nat := @fin_max _ fun i =>
let h : i < a.size := by
get_elem_tactic
a.get ⟨i, h⟩