lean4-htt/tests/lean/run/issue10794.lean
Joachim Breitner c7f57d6a0b
fix: avoid unnecessary branching in match compilation (#10763)
This PR improves match compilation: Branch on variables in the order
suggested by the first remaining alternative, and do not branch when the
first remaining alternative does not require it. This fixes
https://github.com/leanprover/lean4/issues/10749. With `set_option
backwards.match.rowMajor false` the old behavior can be turned on.

(For now this is an experiment to get familiar with the code and the
whole
problem domain. It is likely overly naive.)
2025-10-30 20:05:13 +00:00

36 lines
870 B
Text

/--
error: Dependent elimination failed: Type mismatch when solving this alternative: it has type
motive false
but is expected to have type
motive b✝
-/
#guard_msgs in
def test1 b := match b with
| .(false) => 1
| true => 2
/--
error: Dependent elimination failed: Type mismatch when solving this alternative: it has type
motive false ⋯
but is expected to have type
motive x✝¹ x✝
-/
#guard_msgs in
def test2 : (b : Bool) → (h : b = false) → Nat
| .(false), .(rfl) => 1
| true, _ => 2
-- works
def test3 : (b : Bool) → (h : b = false) → Nat
| .(false), rfl => 1
/--
@ +3:4...11
error: Redundant alternative: Any expression matching
true, x✝
will match one of the preceding alternatives
-/
#guard_msgs (positions := true) in
def test4 : (b : Bool) → (h : b = false) → Nat
| .(false), rfl => 1
| true, _ => 2 -- error here