fix: make sure WF/Fix.lean tolerates MatcherApp.addArg? failures

see #1228
This commit is contained in:
Leonardo de Moura 2022-06-17 17:36:41 -07:00
parent 52a0de00e4
commit bbc196eeb7
3 changed files with 56 additions and 2 deletions

View file

@ -83,8 +83,7 @@ where
| some matcherApp =>
if !Structural.recArgHasLooseBVarsAt recFnName fixedPrefixSize e then
processApp F e
else
let matcherApp ← mapError (matcherApp.addArg F) (fun msg => "failed to add functional argument to 'matcher' application" ++ indentD msg)
else if let some matcherApp ← matcherApp.addArg? F then
if !(← Structural.refinedArgType matcherApp F) then
processApp F e
else
@ -95,6 +94,8 @@ where
let FAlt := xs[numParams - 1]
mkLambdaFVars xs (← loop FAlt altBody)
return { matcherApp with alts := altsNew, discrs := (← matcherApp.discrs.mapM (loop F)) }.toExpr
else
processApp F e
| none =>
match (← toCasesOnApp? e) with
| some casesOnApp =>

View file

@ -982,6 +982,13 @@ def MatcherApp.addArg (matcherApp : MatcherApp) (e : Expr) : MetaM MatcherApp :=
remaining := #[e] ++ matcherApp.remaining
}
/-- Similar `MatcherApp.addArg?`, but returns `none` on failure. -/
def MatcherApp.addArg? (matcherApp : MatcherApp) (e : Expr) : MetaM (Option MatcherApp) :=
try
return some (← matcherApp.addArg e)
catch _ =>
return none
builtin_initialize
registerTraceClass `Meta.Match.match
registerTraceClass `Meta.Match.debug

46
tests/lean/run/1228.lean Normal file
View file

@ -0,0 +1,46 @@
inductive Foo (n : Nat) : Type
| foo (t: Foo n): Foo n
namespace Foo
inductive Bar: Foo n → Prop
theorem ex₁ {s: Foo n} (H: s.Bar): True := by
cases h₁ : s
case foo s' =>
cases h₂ : n; sorry
have: Bar s' := sorry
exact ex₁ this
termination_by _ => sizeOf s
theorem ex₂
{s: Foo n}
(H: s.Bar):
True := by
generalize hs': s = s'
match s' with
| foo s' =>
have: Bar s' := sorry
have hterm: sizeOf s' < sizeOf s := by simp_all_arith
exact ex₂ this
termination_by _ => sizeOf s
theorem ex₃ {s: Foo n} (H: s.Bar): True := by
cases h₁ : s
case foo s' =>
match n with
| 0 => sorry
| _ =>
have: Bar s' := sorry
exact ex₃ this
termination_by _ => sizeOf s
-- it works
theorem ex₄ {s: Foo n} (H: s.Bar): True := by
match s with
| foo s' =>
match n with
| 0 => sorry
| _ =>
have: Bar s' := sorry
exact ex₄ this
termination_by _ => sizeOf s