Skip to content

Conversation

@kim-em
Copy link
Collaborator

@kim-em kim-em commented Dec 2, 2025

This PR fixes a panic in getEqnsFor? when called on matchers generated from match expressions in theorem types.

When a theorem's type contains a match expression (e.g., theorem bar : (match ... with ...) = 0), the compiler generates a matcher like bar.match_1. Calling getEqnsFor? on this matcher would panic with:

PANIC: duplicate normalized declaration name bar.match_1.eq_1 vs. _private...bar.match_1.eq_1

This also affected the try? tactic, which internally uses getEqnsFor?.

We make shouldGenerateEqnThms return false for matchers, since their equations are already generated separately by Lean.Meta.Match.MatchEqs. This prevents the equation generation machinery from attempting to create duplicate equation theorems.

Closes #11461
Closes #10390

🤖 Prepared with Claude Code

When a theorem's type contains a match expression, calling `getEqnsFor?`
on the generated matcher would panic with "duplicate normalized declaration name".

This occurred because matchers have their equations generated separately by
`Lean.Meta.Match.MatchEqs`, but `shouldGenerateEqnThms` didn't check for this,
leading to conflicting equation theorem names.

The fix makes `shouldGenerateEqnThms` return `false` for matchers, since their
equations are already handled by the dedicated matcher equation infrastructure.

Closes #11461

🤖 Prepared with Claude Code

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Dec 2, 2025
@leanprover-community-bot
Copy link
Collaborator

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase c0d5b9b52c31c181db0902b4cc107459f9df6563 --onto 5bd331e85d9d110a29fb3367dbb21854010ffcbd. You can force Mathlib CI using the force-mathlib-ci label. (2025-12-02 01:14:39)

@leanprover-bot
Copy link
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase c0d5b9b52c31c181db0902b4cc107459f9df6563 --onto d3dda9f6d4428a906c096067ecb75e432afc4615. You can force reference manual CI using the force-manual-ci label. (2025-12-02 01:14:40)

@kim-em kim-em marked this pull request as draft December 2, 2025 03:04
@kim-em kim-em added the changelog-language Language features and metaprograms label Dec 2, 2025
@kim-em kim-em marked this pull request as ready for review December 2, 2025 07:53
@kim-em kim-em added this pull request to the merge queue Dec 2, 2025
Merged via the queue into master with commit 2eca5ca Dec 2, 2025
25 of 27 checks passed
algebraic-dev pushed a commit that referenced this pull request Dec 8, 2025
This PR fixes a panic in `getEqnsFor?` when called on matchers generated
from match expressions in theorem types.

When a theorem's type contains a match expression (e.g., `theorem bar :
(match ... with ...) = 0`), the compiler generates a matcher like
`bar.match_1`. Calling `getEqnsFor?` on this matcher would panic with:

```
PANIC: duplicate normalized declaration name bar.match_1.eq_1 vs. _private...bar.match_1.eq_1
```

This also affected the `try?` tactic, which internally uses
`getEqnsFor?`.

We make `shouldGenerateEqnThms` return `false` for matchers, since their
equations are already generated separately by
`Lean.Meta.Match.MatchEqs`. This prevents the equation generation
machinery from attempting to create duplicate equation theorems.

Closes #11461
Closes #10390


🤖 Prepared with Claude Code

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-language Language features and metaprograms toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PANIC in getEqnsFor? when theorem type contains match expression Generating match equations with getEqnsFor? may panic

5 participants