Skip to content

Commit b5b2938

Browse files
committed
fix: spurious warning message in grind
This PR fixes a spurious warning message in `grind`. Closes #10670
1 parent cdaa827 commit b5b2938

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Lean/Elab/Tactic/Grind/Main.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ where
185185
-- If it is an inductive predicate,
186186
-- we also add the constructors (intro rules) as E-matching rules
187187
for ctor in info.ctors do
188-
params ← withRef p <| addEMatchTheorem params id ctor (.default false) minIndexable
188+
-- **Note**: We should not warn if `declName` is an inductive
189+
params ← withRef p <| addEMatchTheorem params id ctor (.default false) minIndexable (warn := False)
189190
else
190191
params ← withRef p <| addEMatchTheorem params id declName (.default false) minIndexable (suggest := true)
191192
| .symbol prio =>
@@ -195,7 +196,7 @@ where
195196

196197
addEMatchTheorem (params : Grind.Params) (id : Ident) (declName : Name)
197198
(kind : Grind.EMatchTheoremKind)
198-
(minIndexable : Bool) (suggest : Bool := false) : MetaM Grind.Params := do
199+
(minIndexable : Bool) (suggest : Bool := false) (warn := true) : MetaM Grind.Params := do
199200
let info ← getAsyncConstInfo declName
200201
match info.kind with
201202
| .thm | .axiom | .ctor =>
@@ -204,7 +205,8 @@ where
204205
ensureNoMinIndexable minIndexable
205206
let thm₁ ← Grind.mkEMatchTheoremForDecl declName (.eqLhs gen) params.symPrios
206207
let thm₂ ← Grind.mkEMatchTheoremForDecl declName (.eqRhs gen) params.symPrios
207-
if params.ematch.containsWithSamePatterns thm₁.origin thm₁.patterns &&
208+
if warn &&
209+
params.ematch.containsWithSamePatterns thm₁.origin thm₁.patterns &&
208210
params.ematch.containsWithSamePatterns thm₂.origin thm₂.patterns then
209211
warnRedundantEMatchArg params.ematch declName
210212
return { params with extra := params.extra.push thm₁ |>.push thm₂ }
@@ -215,7 +217,7 @@ where
215217
Grind.mkEMatchTheoremAndSuggest id declName params.symPrios minIndexable (isParam := true)
216218
else
217219
Grind.mkEMatchTheoremForDecl declName kind params.symPrios (minIndexable := minIndexable)
218-
if params.ematch.containsWithSamePatterns thm.origin thm.patterns then
220+
if warn && params.ematch.containsWithSamePatterns thm.origin thm.patterns then
219221
warnRedundantEMatchArg params.ematch declName
220222
return { params with extra := params.extra.push thm }
221223
| .defn =>

tests/lean/run/grind_10670.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
inductive Foo : Nat → Prop
2+
| one : Foo 1
3+
| two : Foo 2
4+
5+
attribute [grind ·] Foo.one
6+
7+
#guard_msgs in
8+
example {l : Nat} (hl : Foo l) : Foo (3 - l) := by
9+
induction hl with
10+
| one => grind [Foo]
11+
| two => grind

0 commit comments

Comments
 (0)