Skip to content

Commit 14d76cc

Browse files
authored
fix: decreasing_by: preserve variable names of match alts (#10980)
This PR tries to preserve names of pattern variables in match alternatives in `decreasing_by`, by telescoping into the concrete alternative rather than the type of the matcher's alt. Fixes #10976.
1 parent d2f76ad commit 14d76cc

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/Lean/Meta/Match/MatcherApp/Transform.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ private partial def updateAlts (unrefinedArgType : Expr) (typeNew : Expr) (altNu
2222
let typeNew ← whnfD typeNew
2323
match typeNew with
2424
| Expr.forallE _ d b _ =>
25-
let (alt, refined) ← forallBoundedTelescope d (some numParams) fun xs d => do
26-
let alt ← try instantiateLambda alt xs catch _ => throwError "unexpected matcher application, insufficient number of parameters in alternative"
25+
let (alt, refined) ← lambdaBoundedTelescope alt numParams fun xs alt => do
26+
unless xs.size == numParams do
27+
throwError "unexpected matcher application, alternative must have {numParams} parameters"
28+
let d ← try instantiateForall d xs catch _ => throwError "unexpected matcher application, insufficient number of parameters in alternative"
2729
forallBoundedTelescope d (some 1) fun x _ => do
2830
let alt ← mkLambdaFVars x alt -- x is the new argument we are adding to the alternative
2931
let refined ← if refined then

tests/lean/guessLexFailures.lean.expected.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,5 @@ guessLexFailures.lean:131:14-131:31: error: failed to prove termination, possibl
155155
- Use `have`-expressions to prove the remaining goals
156156
- Use `termination_by` to specify a different well-founded relation
157157
- Use `decreasing_by` to specify your own tactic for discharging this kind of goal
158-
m n✝ n : Nat
159-
⊢ n < n✝ + 1
158+
n✝ m n : Nat
159+
⊢ n < n✝

tests/lean/run/issue10976.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- The variable names should be `a1` and `b1`
2+
3+
/--
4+
error: Failed: `fail` tactic was invoked
5+
a1 b1 : Nat
6+
⊢ a1 + b1 < a1.succ + b1.succ
7+
-/
8+
#guard_msgs in
9+
def f (a b : Nat) := match a with
10+
| 0 => 0
11+
| a1+1 => match b with
12+
| 0 => 0
13+
| b1+1 => f a1 b1
14+
termination_by a+b
15+
decreasing_by
16+
fail

0 commit comments

Comments
 (0)