constructorNameAsVariable linter fails when a binder's type is expensive to reduce
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 70/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 領域
- tooling
調査の方向性
Start with src/Lean/Linter/ConstructorAsVariable.lean, especially the Meta.whnf call around line 69 described in the issue, and reproduce the failure by running lean Linter.lean on the supplied example. Check how the linter handles reduction failures and how it identifies inductive types. Done when the example builds without a linter error while the linter still reports constructor names as variables.
索引モデルが issue の本文から書いたものです。
説明
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.
(Not a soundness bug.)
Description
The constructorNameAsVariable linter reduces the type of every named local variable with
Meta.whnf at default transparency. If that reduction is expensive, the linter fails, and Lean
reports the failure as an error. A declaration that elaborates and type-checks then fails to build.
Context
src/Lean/Linter/ConstructorAsVariable.lean (line 69 on master) computes the weak head normal
form of each binder's type to find an inductive type and its constructors:
let ty ← ti.runMetaM ci (instantiateMVars ty >>= Meta.whnf)
Meta.whnf unfolds definitions at default transparency. For a hypothesis whose type is a
proposition, this reduction can evaluate an arbitrary computation. In our case, the hypothesis was
h : r ∈ support c for a probabilistic computation c in VCVio. Its weak head normal form runs
c, which samples a 2^32-bit value.
Steps to Reproduce
/-- A proposition whose weak head normal form needs `2 ^ n`. -/
def Big (n : Nat) : Prop := if 2 ^ n = 0 then True else False
-- The `constructorNameAsVariable` linter reduces the type of `_h` with `Meta.whnf` and fails:
-- "linter Lean.Linter.constructorNameAsVariable failed: maximum recursion depth has been reached".
theorem linted (_h : Big (2 ^ 32)) : True := trivial
-- No error: the same theorem with the linter disabled.
set_option linter.constructorNameAsVariable false in
theorem unlinted (_h : Big (2 ^ 32)) : True := trivial
- Save the file as
Linter.lean. - Run
lean Linter.lean.
Expected behavior: Lean accepts both theorems. The name _h is not the name of a constructor,
so the linter has nothing to report.
Actual behavior: Lean exits with status 1 and reports one error, for linted:
Linter.lean:6:0: error: linter Lean.Linter.constructorNameAsVariable failed: maximum recursion depth has been reached
use `set_option maxRecDepth <num>` to increase limit
use `set_option diagnostics true` to get diagnostic information
Versions
4.35.04.36.04.38.0-nightly-2026-11-19
The result is the same on all three versions. OS: Linux x86_64.
Additional Information
The linter uses the reduced type only to find an inductive type at its head. Two possible changes:
- Reduce with a cheaper function, such as
whnfRat reducible transparency. - Treat a failure of the reduction as "no warning" instead of a linter error.
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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
leanprover/lean4 のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
leanprover/lean4#16681 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
leanprover/lean4#16305 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
leanprover/lean4#16299 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
leanprover/lean4#16257 ·
メンテナーはふだん 1 日以内に返信
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
leanprover/lean4#15683 ·
メンテナーはふだん 1 日以内に返信
leanprover/lean4 の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
speakeasy-api/speakeasy#2159 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
hubverse-org/hubDevs#83 ·
-
garden
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
taecontrol/google-accounts-mcp#92 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信