lean4-htt/tests/lean/run/grind_fin_bug.lean
Leonardo de Moura cce6ce9577
fix: treat outParam arguments as support in e-matching patterns (#12476)
This PR fixes #12245 where `grind` works on `Fin n` but fails on `Fin (n
+ 1)`.

The `outParam` argument (e.g., the `range` parameter of `ToInt`) was
included as a relevant position in the e-matching pattern. The `grind`
normalizer rewrites `↑(n + 1)` to `↑n + 1` inside the range expression,
causing the pattern to no longer match. Since `outParam` arguments are
uniquely determined by type class resolution, they can be safely
wildcarded in patterns — the same reasoning that already applies to
instance-implicit arguments.

Reproducer from the issue:
```lean
example {n : Nat} {a : Fin (n + 1)} {b : Nat} (hb : b < n + 1)
    (h : (a : Nat) < b) : a < ⟨b, hb⟩ := by grind -- fails without fix
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-14 05:05:56 +00:00

19 lines
846 B
Text

-- Issue #12245: grind works on Fin n but fails on Fin (n + 1)
-- The fix is in `getPatternArgKinds`: `outParam` arguments are now treated as support
-- in e-matching patterns. After the next toolchain update, the `attribute` line below
-- can be removed.
example {n : Nat} {a : Fin n} {b : Nat} (hb : b < n)
(h : (a : Nat) < b) : a < ⟨b, hb⟩ := by grind
example {n : Nat} {a : Fin (n + 1)} {b : Nat} (hb : b < n + 1)
(h : (a : Nat) < b) : a < ⟨b, hb⟩ := by grind
example {n : Nat} {a : Fin (n + 2)} {b : Nat} (hb : b < n + 2)
(h : (a : Nat) < b) : a < ⟨b, hb⟩ := by grind
example {n m : Nat} {a : Fin (n + m)} {b : Nat} (hb : b < n + m)
(h : (a : Nat) < b) : a < ⟨b, hb⟩ := by grind
example {n : Nat} {a : Fin (n * 2 + 1)} {b : Nat} (hb : b < n * 2 + 1)
(h : (a : Nat) < b) : a < ⟨b, hb⟩ := by grind