Skip to content

Commit a594f65

Browse files
authored
fix: use withReducibleAndIntances to match ground patterns (#8365)
This PR fixes the transparency mode for ground patterns. This is important for implicit instances. Here is a mwe for an issue detected while testing `grind` in Mathlib. ```lean example (a : Nat) : max a a = a := by grind instance : Max Nat where max := Nat.max example (a : Nat) : max a a = a := by grind -- Should work ```
1 parent 7a6bca5 commit a594f65

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,23 @@ private def matchArg? (c : Choice) (pArg : Expr) (eArg : Expr) : OptionT GoalM C
104104
else if pArg.isBVar then
105105
assign? c pArg.bvarIdx! eArg
106106
else if let some pArg := groundPattern? pArg then
107-
guard (← isEqv pArg eArg <||> withReducible (isDefEq pArg eArg))
107+
/-
108+
We need to use `withReducibleAndIntances` because ground patterns are often instances.
109+
Here is an example
110+
```
111+
instance : Max Nat where
112+
max := Nat.max -- Redefined the instance
113+
114+
example (a : Nat) : max a a = a := by
115+
grind
116+
```
117+
Possible future improvements:
118+
- When `diagnostics` is true, try with `withDefault` and report issue if it succeeds.
119+
- (minor) Only use `withReducibleAndInstances` if the argument is an implicit instance.
120+
Potential issue: some user write `{_ : Class α}` when the instance can be inferred from
121+
explicit arguments.
122+
-/
123+
guard (← isEqv pArg eArg <||> withReducibleAndInstances (isDefEq pArg eArg))
108124
return c
109125
else if let some (pArg, k) := isOffsetPattern? pArg then
110126
assert! Option.isNone <| isOffsetPattern? pArg
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
set_option grind.warning false
2+
3+
example (a : Nat) : max a a = a := by
4+
grind
5+
6+
instance : Max Nat where
7+
max := Nat.max
8+
9+
example (a : Nat) : max a a = a := by
10+
grind

0 commit comments

Comments
 (0)