`grind_pattern` after `attribute [-grind]` revives the erased pattern

Open
#16,244 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
compilers

Research direction

Start with the minimal Lean example in the issue and trace how attribute [-grind] and grind_pattern update the theorem’s patterns used by grind. Check the related command and attribute implementation and existing tests for grind_pattern. Done means the erased pattern stays inactive, so the example fails as expected while the replacement pattern still works when its term is present.

Written by the indexing model from the issue text.

Description

Prerequisites
  • Check that your issue is not already filed:
    https://github.com/leanprover/lean4/issues
  • Reduce the issue to a minimal, self-contained, reproducible test case.
    Avoid dependencies to Mathlib or Batteries.
  • Test your test case against the latest nightly release, for example on
    https://live.lean-lang.org/#project=lean-nightly
    (You can also use the settings there to switch to “Lean nightly”)
  • When reporting a perceived soundness bug: Does it affect lake check --paranoid?
    If in doubt, please reach out on [email protected] for responsible disclosure.
Description

The lemma f_eq has the attribute @[grind =]. After attribute [-grind] f_eq, the command grind_pattern f_eq => h (f n) registers the pattern h (f n) for f_eq. grind then proves a goal about f x with f_eq, but the goal holds no h term.

Context

I wanted to replace the pattern of a library @[grind =] lemma with a different pattern in my own file. To do this, I erased the attribute with attribute [-grind] and then registered the new pattern with grind_pattern.

Steps to Reproduce
  1. Run this file:
def f (n : Nat) : Nat := n + 1
def h (n : Nat) : Nat := n

@[grind =] theorem f_eq (n : Nat) : f n = n + 1 := rfl

attribute [-grind] f_eq
grind_pattern f_eq => h (f n)

example (x : Nat) : f x = x + 1 := by
  grind

Expected behavior: grind fails. The only active pattern for f_eq is h (f n), and the goal holds no h term.

Actual behavior: grind succeeds.

Versions

"4.37.0-nightly-2026-11-03" (from #eval Lean.versionString)
Linux 7.3.1

Additional Information
  • If the file has only the line attribute [-grind] f_eq and no grind_pattern line, grind fails.
  • If f_eq has no grind attribute and the file has only the line grind_pattern f_eq => h (f n), grind fails.
Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Dominant language
Lean
Stars
10.3k
Forks
1.1k
Avg merge
19h 8m
Merged PRs (30d)
421

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from leanprover/lean4

All issues in leanprover/lean4

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.