`simp` fails when it tries to apply a private lemma in the public scope

オープン
#16,660 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
領域
compilers

調査の方向性

Start from the minimal reproduction in the issue: a public section with a private @[simp] theorem x_eq used by simp -failIfUnchanged at h inside an @[expose] definition. The failure is an "Unknown constant" error for the private name, so look at how simp collects and resolves candidate lemmas when run in the public scope. Done means the reproduction no longer errors and simp leaves h unchanged, with private lemmas skipped or handled correctly in that scope.

索引モデルが issue の本文から書いたものです。

説明

bug
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

When simp is run in the public scope and it tries to apply a private (or privately imported) lemma, it fails with an "Unknown constant" error, even if in the end, that lemma wouldn't have been applied (for example, due to typeclass assumptions). Ideally, simp would apply only public lemmas when run in the public scope.

Context

Mathlib's simps attribute has an option to call simp on the generated lemmas, which is currently run in the public scope. This caused an error in an existing definition in a PR which added a private import to a file, even though the lemma simp tried applying wouldn't have been used because of its typeclass assumptions. See the discussion of https://github.com/leanprover-community/mathlib4/pull/46130 for details. However, this issue can be reproduced without any metaprogramming by constructing a definition using tactics.

Steps to Reproduce
module

public section

def x := 0

@[simp]
private theorem x_eq (_ : False) : x = 0 := rfl

@[expose]
def a (h : x = 0) : Nat := by
  simp -failIfUnchanged at h
  exact 0

Expected behavior: simp does nothing.

Actual behavior: simp fails with "Unknown constant _private.«external:file:///lean-nightly/lean-nightly.lean».0.x_eq".

Versions

Lean 4.38.0-nightly-2026-11-20

Additional Information

[Additional information, configuration or data that might be necessary to reproduce the issue]

Impact

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

主要言語
Lean
スター
10.3k
フォーク
1.1k
平均マージ
19時間 8分
マージ済み PR(30日)
421

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

leanprover/lean4 のほかの issue

leanprover/lean4 の issue をすべて見る

似ている issue

Compilers の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。