lean4-htt/tests/lean/run/inductionCheckAltNames.lean
jrr6 d1ec806834
feat: improve error messages in invalid match alternatives (#8368)
This PR improves the error messages produced by invalid pattern-match
alternatives and improves parity in error placement between
pattern-matching tactics and elaborators.

Closes #7170
2025-05-19 17:40:41 +00:00

51 lines
1.7 KiB
Text
Raw 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.

universe u
axiom elimEx (motive : Nat → Nat → Sort u) (x y : Nat)
(diag : (a : Nat) → motive a a)
(upper : (delta a : Nat) → motive a (a + delta.succ))
(lower : (delta a : Nat) → motive (a + delta.succ) a)
: motive y x
/-- error: Invalid alternative name 'lower2': Expected 'diag', 'upper', or 'lower' -/
#guard_msgs in
theorem invalidAlt (p: Nat) : p ≤ q p > q := by
cases p, q using elimEx with
| lower2 /- error -/ d => apply Or.inl; admit
| upper d => apply Or.inr
| diag => apply Or.inl; apply Nat.le_refl
/-- error: Invalid alternative name 'lower2': Expected 'lower' -/
#guard_msgs in
theorem oneMissingAlt (p: Nat) : p ≤ q p > q := by
cases p, q using elimEx with
| upper d => apply Or.inl; admit
| diag => apply Or.inl; apply Nat.le_refl
| lower2 /- error -/ => apply Or.inr
/-- error: Duplicate alternative name 'upper' -/
#guard_msgs in
theorem doubleAlt (p: Nat) : p ≤ q p > q := by
cases p, q using elimEx with
| upper d => apply Or.inl; admit
| upper d /- error -/ => apply Or.inr
| diag => apply Or.inl; apply Nat.le_refl
/--
error: Invalid occurrence of the wildcard alternative `| _ => ...`: It must be the last alternative
-/
#guard_msgs in
theorem invalidWildCard (p: Nat) : p ≤ q p > q := by
cases p, q using elimEx with
| upper d => apply Or.inl; admit
| _ /- error -/ => apply Or.inr
| diag => apply Or.inl; apply Nat.le_refl
/-- error: Invalid alternative name 'lower2': There are no unhandled alternatives -/
#guard_msgs in
theorem noAlt (p: Nat) : p ≤ q p > q := by
cases p, q using elimEx with
| upper d => apply Or.inl; admit
| lower => apply Or.inr
| diag => apply Or.inl; apply Nat.le_refl
| lower2 /- error -/ => apply Or.inr