Skip to content

Commit 9b6c53e

Browse files
committed
fix: grind pattern validation
This PR fixes a bug in the `grind` pattern validation. The bug affected type classes that were propositions. Closes #11477
1 parent f8866dc commit 9b6c53e

File tree

2 files changed

+71
-7
lines changed

2 files changed

+71
-7
lines changed

src/Lean/Meta/Tactic/Grind/EMatchTheorem.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -794,13 +794,6 @@ private def checkCoverage (thmProof : Expr) (numParams : Nat) (bvarsFound : Std.
794794
fvarsFound := update fvarsFound xType
795795
processed := processed.insert fvarId
796796
modified := true
797-
else if (← isProp xType) then
798-
-- If `x` is a proposition, and all theorem variables in `x`s type have already been found
799-
-- add it to `fvarsFound` and mark it as processed.
800-
if checkTypeFVars thmVars fvarsFound xType then
801-
fvarsFound := fvarsFound.insert fvarId
802-
processed := processed.insert fvarId
803-
modified := true
804797
else if (← fvarId.getDecl).binderInfo matches .instImplicit then
805798
-- If `x` is instance implicit, check whether
806799
-- we have found all free variables needed to synthesize instance
@@ -809,6 +802,13 @@ private def checkCoverage (thmProof : Expr) (numParams : Nat) (bvarsFound : Std.
809802
fvarsFound := update fvarsFound xType
810803
processed := processed.insert fvarId
811804
modified := true
805+
else if (← isProp xType) then
806+
-- If `x` is a proposition, and all theorem variables in `x`s type have already been found
807+
-- add it to `fvarsFound` and mark it as processed.
808+
if checkTypeFVars thmVars fvarsFound xType then
809+
fvarsFound := fvarsFound.insert fvarId
810+
processed := processed.insert fvarId
811+
modified := true
812812
if fvarsFound.size == numParams then
813813
return .ok
814814
if !modified then

tests/lean/run/grind_11477.lean

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
class Rel (a: Type u) where
2+
rel: a → a → Prop
3+
4+
class Test {a: Type u} [Rel a] (x: a) (p: outParam (a → Prop)) where
5+
pf: ∀ y: a, Rel.rel x y = p y
6+
7+
theorem test
8+
{a: Type u} [Rel a]
9+
(x y: a)
10+
{p: a → Prop} [Test x p]
11+
: Rel.rel x y = p y
12+
:= by
13+
simp [Test.pf]
14+
15+
grind_pattern test => Rel.rel x y
16+
17+
theorem testGrind
18+
{a: Type u} [Rel a]
19+
(x y: a)
20+
{p: a → Prop} [Test x p]
21+
: Rel.rel x y = p y
22+
:= by
23+
grind
24+
25+
class TestBis {a: Type u} [Rel a] (x: a) (p: outParam (a → Prop)) where
26+
pf: ∀ y: a, Rel.rel x y = p y
27+
28+
instance {a: Type u} [Rel a] (x: a) (p: a → Prop) [TestBis x p]: Test x p where
29+
pf := TestBis.pf
30+
31+
theorem testBisGrind
32+
{a: Type u} [Rel a]
33+
(x y: a)
34+
{p: a → Prop} [TestBis x p]
35+
: Rel.rel x y = p y
36+
:= by
37+
grind
38+
39+
section TestHierarchy
40+
class Refl (a: Type u) [Rel a] where
41+
refl: ∀ x: a, Rel.rel x x
42+
43+
theorem refl
44+
{a: Type u} [Rel a] [Refl a]
45+
(x: a)
46+
: Rel.rel x x
47+
:= by
48+
apply Refl.refl
49+
50+
grind_pattern refl => Rel.rel x x
51+
52+
class AllRel (a: Type u) [Rel a] where
53+
all: ∀ x y: a, Rel.rel x y
54+
55+
instance {a} [Rel a] [AllRel a]: Refl a where
56+
refl := by simp [AllRel.all]
57+
58+
theorem refl_allrel
59+
{a: Type u} [Rel a] [AllRel a]
60+
(x: a)
61+
: Rel.rel x x
62+
:= by
63+
grind
64+
end TestHierarchy

0 commit comments

Comments
 (0)