lean4-htt/tests/lean/run/splitErrors.lean
jrr6 34bd6e8bfd
feat: improve split error messages (#9424)
This PR improves the error messages produced by the `split` tactic,
including suggesting syntax fixes and related tactics with which it
might be confused.

Note that, to avoid clashing with the new error message styling
conventions used in these messages, this PR also updates the formatting
of the message produced by `throwTacticEx`.

Closes #6224
2025-07-18 22:36:10 +00:00

120 lines
3.2 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.

/-! # `split` tactic errors
Assesses error messages and hints produced by the `split` tactic.
-/
/--
error: Tactic `split` failed: Specifying a term to split is not supported yet
Hint: To apply `split` at the hypothesis `h`, use `split at h`:
split a̲t̲ ̲h
-/
#guard_msgs in
example : False := by
have h : if True then True else True := trivial
split h
/-- error: Tactic `split` failed: Specifying a term to split is not supported yet -/
#guard_msgs in
example (x y : Bool) : (if x && y then 1 else 2) > (if x || y then 0 else 1) := by
split x && y
/--
error: Tactic `split` failed: Could not split an `if` or `match` expression in the goal
Hint: Use `set_option trace.split.failure true` to display additional diagnostic information
⊢ False
-/
#guard_msgs in
example : False := by
split
/--
error: Tactic `split` failed: Could not split the goal or any of the following hypotheses: `h1`
Note: `split at *` does not attempt to split at non-propositional hypotheses or those on which other hypotheses depend. It may still be possible to manually split a hypothesis using `split at`
Hint: Use `set_option trace.split.failure true` to display additional diagnostic information
h1 : True
⊢ False
-/
#guard_msgs in
example : False := by
have h1 : True := trivial
split at *
/--
error: Tactic `split` failed: Could not split an `if` or `match` expression in the type `p ∧ q` of `h`
Hint: If you meant to destruct this conjunction, use the `cases` tactic instead
Hint: Use `set_option trace.split.failure true` to display additional diagnostic information
p q : Prop
h : p ∧ q
⊢ p
-/
#guard_msgs in
example {p q : Prop} (h : p ∧ q) : p := by
split at h
/--
error: Tactic `split` failed: Could not split an `if` or `match` expression in the type `Equivalence R` of `h`
Hint: If you meant to destruct this structure, use the `cases` tactic instead
Hint: Use `set_option trace.split.failure true` to display additional diagnostic information
α : Sort u_1
R : αα → Prop
h : Equivalence R
⊢ False
-/
#guard_msgs in
example {R : αα → Prop} (h : Equivalence R) : False := by
split at h
/--
error: Tactic `split` failed: Could not split the goal or any of the following hypotheses: `t`, `use_dep`
Note: `split at *` does not attempt to split at non-propositional hypotheses or those on which other hypotheses depend. It may still be possible to manually split a hypothesis using `split at`
t : True
dep : if 1 ≥ 0 then True else False
use_dep : dep = dep
⊢ False
-/
#guard_msgs in
example : False := by
have t : True := trivial
have dep : if 1 ≥ 0 then True else False := by simp
have use_dep : dep = dep := rfl
set_option trace.split.failure true in
split at *
/--
error: Tactic `split` failed: Could not split an `if` or `match` expression in the type `Nat` of `x`
x : Nat := if true = true then 3 else 4
⊢ False
-/
#guard_msgs in
example : False := by
let x := if true then 3 else 4
set_option trace.split.failure true in
split at x
/--
error: Tactic `split` failed: Could not split an `if` or `match` expression in the type `True` of `h`
Hint: Use `set_option trace.split.failure true` to display additional diagnostic information
h : True
⊢ False
-/
#guard_msgs in
example : False := by
have h : True := trivial
split at h