leanprover / leanprover/lean4

`simp` uses `congr` lemmas that are not visible

Open
#11,436 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

Private lemmas marked as @[congr] from imported modules are used by simp even though they are not visible, causing unknown constant errors.

Steps to Reproduce
  1. Check out the Lake project in this branch: https://github.com/datokrat/lean-bug-reproductions/tree/bugs7
  2. Open Reproductions/Basic.lean and observe the error.

Reproductions/Dependency.lean:

module

public def f : Nat → Nat := sorry

@[congr]
theorem t (h : m = n) : f m = f n := sorry

Reproductions/Basic.lean:

module

import Reproductions.Dependency

/-- error: Unknown constant `_private.Reproductions.Dependency.0.t` -/
#guard_msgs in
theorem u (h : m = n) : f m = f n := by
  simp [h]

Expected behavior:

simp should only use congr lemmas that are visible. (In the given example, theorem u should succeed because simp actually doesn't need to use a specialized congr lemma.)

Actual behavior:

An unknown constant error is caused by simp.

Versions
Lean 4.27.0-nightly-2025-11-30
Target: arm64-apple-darwin24.6.0 macOS
Impact

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

Contributor guide

Open the contributing guide

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.

Research direction

Run the Lake project from the bugs7 branch and reproduce the failure in Reproductions/Basic.lean, using Reproductions/Dependency.lean to understand the imported private congr lemma. Trace simp's congr-lemma handling and ensure theorem u succeeds without an unknown constant for an invisible lemma; rerun the reproduction to verify the fix.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.