lean4-htt/tests/elab/issue13015.lean
Joachim Breitner 861f722844
fix: handle multi-discriminant casesOn in WF unfold equation generation (#13232)
This PR fixes a panic when compiling mutually recursive definitions that
use `casesOn` on indexed inductive types (e.g. `Vect`). The
`splitMatchOrCasesOn` function in `WF.Unfold` asserted
`matcherInfo.numDiscrs = 1`, but for indexed types the casesOn recursor
has multiple discriminants (indices + major premise). The fix uses the
last discriminant (the major premise) and lets the `cases` tactic handle
index discriminants automatically.

Closes #13015

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-01 15:23:13 +00:00

24 lines
983 B
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- Mutually recursive definitions using casesOn on indexed types should not panic.
-- https://github.com/leanprover/lean4/issues/13015
inductive Vect (α : Type u) : Nat → Type u
| nil : Vect α 0
| cons : α → {n : Nat} → Vect α n → Vect α (n+1)
mutual
def zipWithAux (f : α → β → γ) (a : α) (as : Vect α m) (bs : Vect β n) : n = m + 1 → γ × Vect γ m :=
Vect.casesOn (motive := λ k _ ↦ k = m + 1 → γ × Vect γ m) bs
(nil := λ h ↦ Nat.noConfusion h)
(cons := λ (b : β) (k : Nat) (bs : Vect β k) h ↦
Nat.noConfusion h (λ h1 : k = m ↦
((f a b), (zipWith f as (h1 ▸ bs) rfl)))
)
def zipWith (f : α → β → γ) {n : Nat} (as : Vect α n) (bs : Vect β n) : n = n → Vect γ n :=
Vect.casesOn (motive := λ m _ ↦ n = m → Vect γ m) as
(nil := λ _ ↦ Vect.nil)
(cons := λ (a : α) (m : Nat) (as : Vect α m) h ↦
let p := zipWithAux f a as bs h
Vect.cons p.1 p.2
)
end