Kernel: nested-inductive auxiliary name `_nested_1` can be referenced by user declarations when the nested type's name is anonymous/macro-scoped
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- compilers
Direzione di ricerca
Start with src/kernel/inductive.cpp, especially elim_nested_inductive_fn::replace_if_nested and check_no_nested_aux, which the issue identifies as the name creation and validation paths. Reproduce the case with the supplied Lean file, then trace how anonymous and macro-scoped names are minted and checked. Done means addDeclCore rejects the reproduced declaration with an unknown constant error.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- When reporting a perceived soundness bug: Does it affect
lake check --paranoid?
(Not believed to be a soundness bug: no inconsistency was derived.)
Description
The kernel accepts an inductive T whose constructor T.bad : _nested_1 → T refers to a
constant that does not exist, and stores T.bad with a different type than declared.
When T is nested (T.mk : J T → T), the kernel replaces J T by an auxiliary type it
names _nested + J and declares that name in a temporary environment. User declarations
are kept from naming these auxiliaries by check_no_nested_aux, which rejects any constant
whose name has the prefix _nested. But if J's name is anonymous (as here) or
macro-scoped (e.g. [email protected]._hyg.1, which macro-generated inductives have), the minted name is
_nested_1 or [email protected]._hyg.1. Neither has _nested as a prefix, so the user can
name it, it resolves to the auxiliary during checking, and the restore pass then rewrites it
to J T.
Reachable through addDecl or a crafted .olean (the elaborator does not create an
anonymous inductive). No inconsistency was derived; the environment ends up containing a
constructor whose declared type mentioned a constant that is declared nowhere.
Steps to Reproduce
Save as NestedAuxUndeclaredConstant.lean and run lean NestedAuxUndeclaredConstant.lean:
import Lean
open Lean Elab Command
-- inductive <anonymous> (α : Type) : Type | mk : α → <anonymous> α
def declJ : Declaration := .inductDecl [] 1 [{
name := .anonymous, type := .forallE `α (.sort 1) (.sort 1) .default,
ctors := [{ name := `AnonMk,
type := .forallE `α (.sort 1) (.forallE `a (.bvar 0) (.app (.const .anonymous []) (.bvar 1)) .default) .implicit }] }] false
-- inductive T : Type | mk : <anonymous> T → T | bad : _nested_1 → T
def declT : Declaration := .inductDecl [] 0 [{
name := `T, type := .sort 1,
ctors := [{ name := `T.mk, type := .forallE `x (.app (.const .anonymous []) (.const `T [])) (.const `T []) .default },
{ name := `T.bad, type := .forallE `x (.const `_nested_1 []) (.const `T []) .default }] }] false
#eval show CommandElabM Unit from do
let .ok env := (← getEnv).addDeclCore 0 512 declJ none | throwError "J rejected"
match env.addDeclCore 0 512 declT none with
| .error e => logInfo m!"T rejected: {e.toMessageData {}}"
| .ok env =>
logInfo m!"T ACCEPTED, although its constructor T.bad mentions the undeclared constant _nested_1"
logInfo m!"_nested_1 declared afterwards? {(env.find? `_nested_1).isSome}"
logInfo m!"T.bad stored as: {(env.find? `T.bad).get!.type}"
Expected output if the kernel were correct: T rejected: unknown constant '_nested_1'. Actual output (Lean 4.35.0, and 4.37.0-nightly-2026-11-14, commit 62e0cf0):
Actual behavior:
T ACCEPTED, although its constructor T.bad mentions the undeclared constant _nested_1
_nested_1 declared afterwards? false
T.bad stored as: [anonymous] T → T
Versions
Lean 4.35.0, 4.36.0 (arm64-apple-darwin, macOS / Darwin 25.6.0), and 4.37.0-nightly-2026-11-14 (commit 62e0cf0).
Additional Information
Where it is in the kernel (leanprover/lean4 master, commit e048ef7, 2026-11-16):
src/kernel/inductive.cpp
-
Line 1093,
elim_nested_inductive_fn::replace_if_nested:name auxJ_name = mk_unique_name(*g_nested + J_name);mk_unique_name(line 989) appends an index withappend_after, which for an anonymous
J_nameproduces the atomic name_nested_1, and for a macro-scoped name puts the index
before the macro scopes. Neither result is under the prefix_nested. -
Lines 1210-1219,
check_no_nested_aux: testsis_prefix_of(*g_nested, const_name(e)),
which is false for these names, so the user's reference is not rejected.
Possible fix: after minting auxJ_name, check is_prefix_of(*g_nested, auxJ_name) and, if it
fails, mint the name under a fixed prefix such as _nested._aux instead.
- Lingua principale
- Lean
- Stelle
- 10.3k
- Fork
- 1.1k
- Merge medio
- 19h 8m
- PR unite (30g)
- 421
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di leanprover/lean4
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
leanprover/lean4#16681 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
leanprover/lean4#16305 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
leanprover/lean4#16299 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
leanprover/lean4#16257 ·
I maintainer di solito rispondono entro 1 giorno
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
leanprover/lean4#15683 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di leanprover/lean4
Issue simili
-
bug fixed form parser medium priority tokenizer
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
swc-project/swc-next-issues#817 ·
-
Magma mode: div:=, mod:= and the other keyword assignments (join:=, meet:=, diff:=, sdiff:=, and:=, or:=, xor:=) are refusedForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
sagemathinc/sagebrush#1683 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
microts: a model local that every branch assigns raises unused_assignments in the generated RustApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 80/100
pocket-stack/pocketjs#756 ·