module
public import Batteries.Tactic.PermuteGoals
public import Mathlib.Tactic.Basic
public import Mathlib.Tactic.Conv
public import Mathlib.Tactic.Linter.Multigoal
public import Mathlib.Tactic.SuccessIfFailWithMsg
public import Mathlib.Util.SleepHeartbeats
set_option linter.style.multiGoal true
-- A deactivated linter does nothing.
set_option linter.style.multiGoal false in
example : True := by
by_cases 0 = 0
exact .intro
exact .intro
/--
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
exact .intro
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example : True := by
by_cases 0 = 0
exact .intro
exact .intro
/--
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
assumption
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example {n : Nat} (hn : n = 0) : n + 0 = 0 := by
conv =>
congr
rw [← Nat.add_zero 0]
conv_lhs =>
congr
rw [← Nat.add_zero n]
rfl
conv_rhs =>
rw [← Nat.add_zero 0]
congr
rfl
rfl
by_cases 0 = 0
assumption
assumption
-- The linter works correctly with `pick_goal` and `on_goal`.
/--
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
trivial
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example : True ∧ True ∧ True := by
constructor
on_goal 2 =>
constructor
trivial
trivial
trivial
/--
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
exact hq
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example {p q : Prop} (hp : p) (hq : q) : p ∧ q := by
constructor
pick_goal 2
exact hq
exact hp
set_option linter.unusedTactic false in
/--
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
rfl
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example (p : Prop) (hp : p) : (0 = 0 ∧ p) ∨ 0 = 0 := by
iterate left; decide
repeat' left; decide
refine Or.inl ⟨?_, ?_⟩
rfl
assumption
/--
warning: The following tactic starts with 3 goals and ends with 2 goals, 2 of which are not operated on.
rfl
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
---
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
trivial
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example : 0 = 0 ∧ 0 = 0 ∧ 0 = 0 := by
refine ⟨?_, ?_, ?_⟩
rfl
trivial
rfl
example (p : Bool) : 0 = 0 := by
cases p
case' false => rfl
case' true => rfl
-- `assumption'` is allowed, as it is useful precisely when there are multiple active goals.
example (p : Bool) (f : False) {h : 0 = 0} : 0 = 0 ∧ 0 = 1 := by
cases p <;>
constructor
assumption'
all_goals cases f
-- `·` is ignored.
example : True ∧ True := by
constructor
· exact .intro
· exact .intro
-- `focus` is ignored.
example : True ∧ True := by
constructor
focus
exact .intro
focus
exact .intro
-- parentheses are allowed
example : True ∧ True ∧ True := by
refine ⟨?_, ?_, ?_⟩; (· simp); { simp }; simp
example : 1 = 1 := by
sleep_heartbeats 1000
rfl
-- We test that a tactic closing all remaining goals does not trigger the linter.
macro "bi_trivial" : tactic => `(tactic| (trivial; trivial))
example : True ∧ True := by
constructor
bi_trivial
-- Exclude `fail_if_success` and `success_if_fail_with_msg` from linting.
example : True := by
fail_if_success done
success_if_fail_with_msg "internal exception #5" done
exact .intro
/-!
Testing that it does not flag tactics that do nothing.
This used to trigger the multigoal linter.
-/
elab "my_skip" : tactic => pure ()
set_option linter.unusedTactic false in
example : True := by
my_skip
trivial
-- Test the linter applies within have statements
/--
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
trivial
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example : true ∧ true := by
have : true ∧ true := by
constructor
trivial
trivial
exact this
-- Test that `grind` interactive mode is treated properly, following the above tests
-- we have to pick slightly less trivial goals that `grind only` will not immediately close
section grind_interactive
variable {x y z : Nat}
/--
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
finish
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example (hx : x = 0 ∨ x = 1) (hy : y = 0 ∨ y = 1) : x ≤ 1 := by
grind =>
cases #484a
finish
finish
-- `focus` is ignored.
example (hx : x = 0 ∨ x = 1) (hy : y = 0 ∨ y = 1) : x ≤ 1 := by
grind =>
cases #484a
focus finish
focus finish
-- `next` is ignored.
example (hx : x = 0 ∨ x = 1) (hy : y = 0 ∨ y = 1) : x ≤ 1 := by
grind =>
cases #484a
next => finish
finish
-- Exclude `skip` from linting.
example (hx : x = 0 ∨ x = 1) (hy : y = 0 ∨ y = 1) : x ≤ 1 := by
grind =>
cases #484a
skip
· finish
· finish
-- Test the linter applies within have statements
/--
warning: The following tactic starts with 2 goals and ends with 1 goal, 1 of which is not operated on.
trivial
Please focus on the current goal, for instance using `·` (typed as "\.").
Note: This linter can be disabled with `set_option linter.style.multiGoal false`
-/
#guard_msgs in
example (hx : x = 0 ∨ x = 1) : x ≤ 1 := by
grind =>
have : true ∧ true := by
constructor
trivial
trivial
cases #01c5
-- excluded tactics
example (hx : x = 0 ∨ x = 1) : x ≤ 1 := by
grind =>
fail_if_success cases #1234
finish
example (hx : x = 0 ∨ x = 1) (hy : y = 0 ∨ y = 1) : x ≤ 1 := by
grind =>
first (cases #484a) (cases #01c5)
first (cases #484a) (cases #01c5)
first (cases #484a) (cases #01c5)
example (hx : x = 0 ∨ x = 1) (hy : y = 0 ∨ y = 1) : x ≤ 1 := by
grind =>
cases #484a
repeat finish
example (hx : x = 0 ∨ x = 1) (hy : y = 0 ∨ y = 1) : x ≤ 1 := by
grind =>
cases #484a
all_goals finish
example (hx : x = 0 ∨ x = 1) (hy : y = 0 ∨ y = 1) : x ≤ 1 := by
grind =>
cases #484a
any_goals finish
end grind_interactive
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet am 2026-11-24)
¤
*© Formatika GbR, Deutschland