Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: better failures for
linear_combination
(#15791)
The implementation of `linear_combination` is as a macro performing effectively `refine ******; ring`. If the term provided to `refine` fails to elaborate, Lean inserts sorries where needed and then continues on to `ring`. This produces a confusing error message. For example, the problem ```lean example (x y : ℤ) (h1 : x * y + 2 * x = 1) (h2 : x = y) : x * y + 2 * x = 1 := by linear_combination h1 + (0 : ℝ) * h2 ``` produces both the "true" error message ``` application type mismatch Mathlib.Tactic.LinearCombination.c_mul_pf h2 0 argument 0 has type ℝ : Type but is expected to have type ℤ : Type ``` and the "tactic is confused because it persevered when it shouldn't have" error message ``` ring failed, ring expressions not equal x y : ℤ h1 : x * y + 2 * x = 1 h2 : x = y ⊢ -(x * sorryAx ℤ true) + y * sorryAx ℤ true = 0 ``` This PR fixes this by strategically inserting a `Term.withoutErrToSorry`. In examples such as the above, it now stops after the `refine`, so the second error message does not appear.
- Loading branch information